Forward geocoding from the iPhone

前端 未结 7 1104
耶瑟儿~
耶瑟儿~ 2020-11-28 05:20

Given that the mapkit doesn\'t provide forward geocoding functionality today, can anyone provide help on how I can i use a search bar to return a latitude and longitude coor

7条回答
  •  不知归路
    2020-11-28 06:25

    I have created SVGeocoder, a simple forward and reverse geocoder class for iOS. It uses the Google Geocoding API as well and returns an MKPlacemark.

    This is how you geocode an address string:

    NSString *addressString = @"3245 St-Denis, Montreal"
    SVGeocoder *geocodeRequest = [[SVGeocoder alloc] initWithAddress:addressString];
    [geocodeRequest setDelegate:self];
    [geocodeRequest startAsynchronous];
    

    And you reverse geocode an CLLocationCoordinate2D object like this:

    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(45.54181, -73.62928);
    SVGeocoder *rGeocoderRequest = [[SVGeocoder alloc] initWithCoordinate:coordinate];
    [rGeocoderRequest setDelegate:self];
    [rGeocoderRequest startAsynchronous];
    

    The SVGeocoderDelegate offers these 2 methods:

    - (void)geocoder:(SVGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark;
    - (void)geocoder:(SVGeocoder *)geocoder didFailWithError:(NSError *)error;
    

提交回复
热议问题