Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get location coordinates for a place using Google Places API?

I am implementing Google Places API, using auto complete I do get place id, now by using place id I want to find the location coordinate for that place. GMSPlace doesn't return the geometry location. I searched but didn't get any help.

GMSPlacesClient *placeClient=[GMSPlacesClient sharedClient];
GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init];
filter.type = kGMSPlacesAutocompleteTypeFilterEstablishment;

[placeClient autocompleteQuery:str
                        bounds:nil
                        filter:filter
                      callback:^(NSArray *results, NSError *error) {
                          if (error != nil) {
                              NSLog(@"Autocomplete error %@", [error localizedDescription]);
                              return;
                          }

                          for (GMSAutocompletePrediction* result in results) {
                              //NSLog(@"Result '%@'", result.attributedFullText.string);
                              [placeName addObject:[NSString stringWithFormat:@"%@",result.attributedFullText.string]];
                              [placeID addObject:[NSString stringWithFormat:@"%@",result.placeID]];
                          }

                   NSLog(@"%@",placeName);
                   NSLog(@"%@",placeName);
   }];
}   
like image 919
kishan Avatar asked Mar 10 '23 23:03

kishan


2 Answers

I think you can get place details by using place id like this

NSString *placeID = @"ChIJV4k8_9UodTERU5KXbkYpSYs";

[_placesClient lookUpPlaceID:placeID callback:^(GMSPlace *place, NSError *error) {
  if (error != nil) {
    NSLog(@"Place Details error %@", [error localizedDescription]);
    return;
  }

  if (place != nil) {
    NSLog(@"Place name %@", place.name);
    NSLog(@"Place address %@", place.formattedAddress);
    NSLog(@"Place placeID %@", place.placeID);
    NSLog(@"Place attributions %@", place.attributions);
  } else {
    NSLog(@"No place details for %@", placeID);
  }
}];

reference : here

like image 193
Himanth Avatar answered Apr 30 '23 11:04

Himanth


You can get place detail from place id. check this Dock. This call will return GMSPlace. GSMPlace have property coordinate.

like image 23
Jignesh Agola Avatar answered Apr 30 '23 13:04

Jignesh Agola