0
votes

I want to find the place name from lat and long.I am using google place api. How can I achieve this

Now I can search for nearby with that lat and long using this

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere

1

1 Answers

1
votes

You can use MKReverseGeoCoder to get the name, district, info, etc. of a given latitude and longtitude. However, notice that it is deprecated.

The ViewController should be the delegate of MKReverseGeocoderDelegate. A sample usage of MKReverseGeoCoder is;

- (void)viewDidLoad {
    CLLocationCoordinate2D coordinates;

    coordinates.latitude = 33.8670522;
    coordinates.longitude = 151.1957362;

    CLLocation *location = [[CLLocation alloc] initWithLatitude:coordinates.latitude longitude:coordinates.longitude];

    MKReverseGeocoder* rev = [[MKReverseGeocoder alloc] initWithCoordinate:location.coordinate];
    rev.delegate = self;
    [rev start];
    [super viewDidLoad];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
    NSLog(@"Error with reverse geo coder.");
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {

    NSLog(@"Geo coder finished successfully");

    NSString *administrativeArea = placemark.administrativeArea;
    NSString *thoroughfare = placemark.thoroughfare;

    NSLog(@"%@ %@", administrativeArea, thoroughfare);
}