Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find polygon of City or region on Map

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?

like image 776
PlusInfosys Avatar asked Oct 28 '25 21:10

PlusInfosys


1 Answers

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()
like image 141
M Reza Avatar answered Oct 30 '25 14:10

M Reza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!