P
P
PRTZ2014-04-25 09:37:14
PHP
PRTZ, 2014-04-25 09:37:14

How to determine the territory of which country they belong to by coordinates?

Hey!
We use OSM and MapBox.
Given: individual points or an array of points on the map. The coordinates of these points are known.
Question: how to return the name of the state to which they belong to the available coordinates?
Good mood to you all!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
moryakov, 2014-04-25
@moryakov

If you use OSM - you can try using nominatim

private function  callNominatim($dLat, $dLon, $iZoom) {
   if ($iZoom<10) 
   $iZoom=12;
    $request_url= sprintf("http://nominatim.openstreetmap.org/reverse?format=json&lat=%.6F&lon=%.6F&zoom=%01d&addressdetails=1",$dLat,$dLon,$iZoom);
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $request_url);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $response = curl_exec($ch);
   curl_close($ch);
   return $response;
}

See response fields.
Good luck.

E
Egor Kazantsev, 2014-04-25
@saintbyte

If it's more difficult ... then unload planet.osm and then unload points, paths and then count the occurrence of a point in a polygon, and for a polygon, see tags like admin_level = 1 =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question