2

Is there any way to get GSMAddress from placeID. I am interested in getting the address by using the placeID obtained from autocompleteQuery method.

P.S: I have a placeID and finding a way to get corresponding GMSAddress in iOS.

I found a thread here but that does not help.

Thanks,

Community
  • 1
  • 1
Vivek Molkar
  • 3,910
  • 1
  • 34
  • 46

2 Answers2

5

After autocomplete, we do a place look up, then pass the coordinates to GMSGeocoder to retrieve the details, but I am still missing street_name and street_number.

CLLocationCoordinate2D addressCoordinates = CLLocationCoordinate2DMake(latitude,longitude);

GMSGeocoder* coder = [[GMSGeocoder alloc] init];
[coder reverseGeocodeCoordinate:addressCoordinates completionHandler:^(GMSReverseGeocodeResponse *results, NSError *error) {

    if (error) {
        NSLog(@"Error %@", error.description);
    } else {
        GMSAddress* address = [results firstResult];
        NSLog(@"thoroughfare %@",address.thoroughfare);
        NSLog(@"locality %@",address.locality);
        NSLog(@"subLocality %@",address.subLocality);
        NSLog(@"administrativeArea %@",address.administrativeArea);
        NSLog(@"postalCode %@",address.postalCode);
        NSLog(@"country %@",address.country);
        NSLog(@"lines %@",address.lines);
    }
}];

I'm thinking of switching to iOS's own reverse geocoder.

[CLGeocoder reverseGeocodeLocation:[[CLLocation alloc] initWithLatitude:latitude longitude:longitude] completionHandler:
 ^(NSArray* placemarks, NSError* error) {
bendigi
  • 590
  • 6
  • 15
  • I want exactly opposite things. get lat long from address.. Hows it possible from GMSGeocoder !! – Solid Soft Oct 05 '16 at 12:00
  • This can get street name and street number. See my answer in swift 4.1 Xcode 9.4.1. You can get even village name details also. https://stackoverflow.com/questions/16647996/get-location-name-from-latitude-longitude-in-ios/51797299#51797299 – Naresh Aug 11 '18 at 09:10
0

It seems there is no direct way to get the GSMAddress from GMSPlace placeID.

One way that I figured out is to use GMSGeocoder().reverseGeocodeCoordinate method along with coordinate property from GMSPlace.

The steps I followed can be summed as:

  1. Use lookUpPlaceID method to find the coordinates
  2. Reverse geocode using the coordinates obtained from lookUpPlaceID

Code is as follows:

    placesClient?.lookUpPlaceID(placeID, callback: {
        (place, error) -> Void in
        // Get place.coordinate
        GMSGeocoder().reverseGeocodeCoordinate(place!.coordinate, completionHandler: {
            (response, error) -> Void in
            for addObj in response.results() {
                // Address object
            }
        })
    })

Comments and better solutions are welcome.

Vivek Molkar
  • 3,910
  • 1
  • 34
  • 46
  • Only issue I have is not being able to get the street_number separated from the street_name. See below in my code snippet – bendigi Oct 29 '15 at 09:07
  • @ bendigi, please see my answer https://stackoverflow.com/questions/16647996/get-location-name-from-latitude-longitude-in-ios/51797299#51797299 – Naresh Aug 11 '18 at 09:18