Reputation: 1341
I want to know the user's current location using Google. I know how to get the user's altitude and longitude using the mapKit but i don't know how to translate it as a location or an address (street name, city, country). I did a few search and all I found was using NSURL to access a given link that accesses the Google Places. however, the one available is to list the places nearby the user. so how can I know the user's current location? Note: I'm not using Apple's Map since my country isn't included and Google is more supporting it.
Upvotes: 0
Views: 1864
Reputation: 3604
There's no reason to use the Web API, the iOS SDK already handles this using the GMSGeocoder
class. Here's an example in Swift of how to convert the user's current location into an address:
let geocoder = GMSGeocoder()
geocoder.reverseGeocodeCoordinate(currentLocation.coordinate) { (response, error) -> Void in
print("Response: \(response.firstResult())")
print("Error: \(error)")
}
Upvotes: 0
Reputation: 2606
You can use the reverse geocoding services.
Here are the docs:
https://developers.google.com/maps/documentation/geocoding/?hl=en#ReverseGeocoding
Example request (JSON):
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
Get JSON data on iOS:
Not getting json response in google query of longitude and latitude in iOS?
For parsing JSON object in iOS, this answer could be usefull for you:
How to parse specific googlemaps API webservices JSON repsonse
Upvotes: 2