Reputation: 3436
I want to draw a border around the city or the area user has searched on the map. I am using Google Place API to find Lattitude and Longitude of Location. But I also want boundary of City or area. So I can draw a polygon around that area to show.
For Example, If User search "New York, USA", I want to draw overlay covering only New York City on map.
Is there any API which I can use in ios to find the whole region on the map?
Upvotes: 3
Views: 4650
Reputation: 19758
Google does not provide such API, but you can get polygon coordinates in geojson format for a city using OpenStreetMap.
You can convert the response to use on maps by several libraries like GEOSwift.
Example:
https://nominatim.openstreetmap.org/search.php?q=New+York&polygon_geojson=1&format=json
let url = URL(string: "https://nominatim.openstreetmap.org/search.php?q=New+York&polygon_geojson=1&format=json")!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!) // Here convert the data to show on map
}
task.resume()
Upvotes: 8