I'm using swift and the google Maps API. I was curious if it was possible to detect which village I'm in? For example if I'm in New York City detect if I'm in east village based on my GPS coordinates. Is there a way for the API to do this or is my best bet to run a serious of comparisons on the coordinates and if they all meet the users current coordinates then assume they are in this village?
Asked
Active
Viewed 67 times
1
-
Are you able to get current location's latitude, longitude? – iDeveloper Mar 16 '17 at 05:15
-
Yes I have the current longitude and latitude – mocode9 Mar 16 '17 at 05:21
-
Than you can easily convert current location's latitude, longitude to current Address/Area. – iDeveloper Mar 16 '17 at 05:25
-
With Maps or Places API? I'm not really sure how I would do that. – mocode9 Mar 16 '17 at 05:47
-
1Please see This http://stackoverflow.com/questions/27735835/convert-coordinates-to-city-name It may be helped. – iDeveloper Mar 16 '17 at 05:55
-
In the maps API is there a way to use the place id to get directions from current location to the place id? – mocode9 Mar 16 '17 at 06:23
1 Answers
0
You can use CLGeocoder from CoreLocation framework to obtain information based on coordinates
let geocoder: CLGeocoder = CLGeocoder()
let location: CLLocation = // your location here
geocoder.reverseGeocodeLocation(location, completionHandler: { (placemarks: [CLPlacemark]?, error: Error?) -> (Void) in
if let placemarks = placemarks, !placemarks.isEmpty
{
if let city = placemarks[0].locality, let sublocality = placemarks[0].subLocality
{
print("You're in \(sublocality) at \(city)")
}
}
else
{
print("No info related to your location")
}
})

Adolfo
- 1,862
- 13
- 19
-
This is the right idea but not working for my needs. It tells you you're in Manhattan when using any coordinate in NYC when in reality I'd like to know if I'm in East Village, Tribeca, Lower Manhattan. Those types of sublocalitys but nothing seems to be able to handle that :/ – mocode9 Mar 18 '17 at 19:47
-
Take a look at CLPlacemark properties and test with the different properties availables. – Adolfo Mar 18 '17 at 23:26
-
I have. None ever tell you the village. Closest you can get is "Manhattan" which isn't wrong but it's not as specific as I'd like to get. – mocode9 Mar 18 '17 at 23:28