Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected fields do not always appear in the MBGeocodedPlacemark #167

Open
johnnewman opened this issue Nov 14, 2018 · 1 comment
Open

Expected fields do not always appear in the MBGeocodedPlacemark #167

johnnewman opened this issue Nov 14, 2018 · 1 comment
Labels

Comments

@johnnewman
Copy link

johnnewman commented Nov 14, 2018

Using v0.10.0.

If I reverse geocode a point in the water of the San Francisco Bay, "California" does not appear as an administrativeRegion on the MBGeocodedPlacemark. If I print the addressDictionary of the placemark, I see that the name is California, but it is not placed under the state key.

Sample code:

CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(37.763778227711242, -122.32790567148118);
MBGeocoder *geocoder = [[MBGeocoder alloc] initWithAccessToken:<token>];
MBReverseGeocodeOptions *options = [[MBReverseGeocodeOptions alloc] initWithCoordinate:coordinate];
[geocoder geocodeWithOptions:options completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) {
        
    NSLog(@"%@", [placemarks[0] addressDictionary]);
      
}];

Output:

{
    ISOCountryCode = US;
    country = "United States";
    formattedAddressLines =     (
        "United States"
    );
    name = California;
}

This makes it challenging to properly format and display reverse geocode data that is powered by a dynamic location at run time. If I reverse geocode a location that has a street address, it likely has a state field.

Below is the addressDictionary of a reverse geocode coordinate in downtown San Francisco. The state is now there. (37.794291209161685, -122.412848997168)

{
    ISOCountryCode = US;
    city = "San Francisco";
    country = "United States";
    formattedAddressLines =     (
        "1187 Washington Street",
        "San Francisco",
        "California 94108",
        "United States"
    );
    name = "Washington Street";
    postalCode = 94108;
    state = California;
    street = "Washington Street";
    subAdministrativeArea = "San Francisco";
    subLocality = "Nob Hill";
    subThoroughfare = 1187;
    thoroughfare = "Washington Street";
}
@johnnewman johnnewman changed the title Expected fields do always not appear in the MBGeocodedPlacemark Expected fields do not always appear in the MBGeocodedPlacemark Nov 14, 2018
@1ec5
Copy link
Contributor

1ec5 commented Jan 23, 2019

Specifically, this is happening because the placemark is itself a region, but Placemark is looking for containing placemarks that are regions:

if let regionName = administrativeRegion?.name {
postalAddress.state = regionName
}
@objc open var administrativeRegion: Placemark? {
return superiorPlacemarks?.lazy.filter { $0.scope == .region }.last
}

The same behavior applies to all the other “Accessing Containing Placemarks” properties, such as postalCode. The fix would be to conditionally fall back to self if self has a matching scope.

@1ec5 1ec5 added the bug label Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants