How to get Coordinates from Google Places API in ios Swift
Asked Answered
R

2

5

I am using Alamofire and SwiftyJSON to auto complete Google Places. I integrated it well and good like this :

enter image description here

Now, what I need is if I select a place from the table view, it is selected in the text field. But how can I get the respective latitude and longitude of that place, so that I can add annotation of that place in MapKit

Is it legal to get details from Google Place API and display them on apple's MapKit? I got this doubt after seeing Viking's question

Rapping answered 6/1, 2016 at 19:40 Comment(3)
First of all, is it possible?Rapping
IIRC you need to make a 2nd query that uses the place IDLogician
can you please explainRapping
M
2

You can get the coordinates from the GMSPlace object. See the documentation.

Regarding if you can use google places alongside apple map, no you can't. As stated in their Terms of Use

Make sure that any maps used by your app to show the location of places retrieved from the Google Places API for iOS are Google maps.

Mascara answered 6/1, 2016 at 21:25 Comment(2)
That is the thing. I am using Apple Maps along with a text box. In that text box I have added Google AutoComplete Places. So if I dont add annotation for that google place in apple map, will that be okay? Can I use both of them in a single view controller?Rapping
As long as you don't show the results in the map in any way it should be fine. I mean you can show the results in a tableview, but you can never add annotations on the map based on the data.Mascara
T
13

Maybe i m bit late but stil as a tuttorial i m posting this answer you can simply get the coordinates like this

// Handle the user's selection 

public func viewController(viewController: GMSAutocompleteViewController, didAutocompleteWithPlace place: GMSPlace) {
    var lat = place.coordinate.latitude
    var lon = place.coordinate.longitude
    print("lat lon",lat,lon)

}
Teal answered 21/8, 2016 at 18:40 Comment(3)
Okay where to call this method?Northrop
It's showing same coordinate everytimeNorthrop
@KrunalNagvadia I got same issue, always getting same coordinates, did you manage solve it?Murillo
M
2

You can get the coordinates from the GMSPlace object. See the documentation.

Regarding if you can use google places alongside apple map, no you can't. As stated in their Terms of Use

Make sure that any maps used by your app to show the location of places retrieved from the Google Places API for iOS are Google maps.

Mascara answered 6/1, 2016 at 21:25 Comment(2)
That is the thing. I am using Apple Maps along with a text box. In that text box I have added Google AutoComplete Places. So if I dont add annotation for that google place in apple map, will that be okay? Can I use both of them in a single view controller?Rapping
As long as you don't show the results in the map in any way it should be fine. I mean you can show the results in a tableview, but you can never add annotations on the map based on the data.Mascara

© 2022 - 2024 — McMap. All rights reserved.