Free Geocodding with OSM
I started new job because someone said that it costs 5k and 2 weeks, because someone said that it’s “handjob” (sorry for my english) :)
PROBLEM: I need to get Cities, suburbs, streets and coordinates of them but I have no idea from where I can start.
POWER OF OSM: OSM as Open Street Map is open source map for all and doesn’t asks for API-KEY like google or money?
In short there is Overpass Turbo which can convert map to CSV or JSON. But you need some codes to get what you need, but it’s json has some problems for example with Coordinates, so you need to use nominatim for that.
http://overpass-turbo.eu/
https://www.openstreetmap.org/
https://www.nominatim.org/
The code to get the name of the Cities that the map sees
[out:csv(“name”)];
(
node[“place”=”city”]({{bbox}}); ან
node[“place”=”town”]({{bbox}});ან
node[“place”=”village”]({{bbox}});
);
out body;
>;
out skel qt;
or from where ever you want
[out:csv(“name”;false)];
area[name=”საქართველო”];
node(area)[“place”=”city”][name];ან
node(area)[“place”=”town”][name];ან
node(area)[“place”=”village”][name];
out;
The code to get the name of the suburbs that the map sees
node[“place”=”suburb”]({{bbox}});
or
node(area)[“place”=”suburb”][name];
In the case to get street names it’s not good alternative to take data from map view it’s better to use this code but there will be some duplicated streets because of users but I am sure group by query in sql is not 5k job.
[out:csv(“name:ka”)];
area[name=”საღორია”][place=”suburb”];
way(area)[highway~”(living_street|residential)”];
out body;
>;
out skel qt;
To get Coordiantes php code:
$ch = curl_init();
$new = str_replace(‘ ‘, ‘%20’, ‘ძველი თბილისი’->title);
if (substr($new, 0, 3) == “\xef\xbb\xbf”) {
$new = substr($new, 3);
}
$url = ‘https://nominatim.openstreetmap.org/search?q='.$new.'&format=geojson';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5’);
$html = curl_exec($ch);
P.s
Need a better job