Monday, October 15, 2018

Display an address on a map without google api

Two months ago i discovered that Geocoding API of google allows 1 map display per day.
Now i'm on a project that needs to display an address marker on a map, since we are in developement phase, i'm not ready to pay 200$ to enable "up to 200$' use of google api.

Here is an alternative using nominatim and openstreetmap.
Long life to opensource.

Be careful, this code supposes that there is one lon,lat forsame address, then you must mention full address to get the waiting for result.


            




The map displayed at the end of the post is printed using the script above :) where mapdiv is an html div inside your page Be careful when importing jquery (do you have another import ? if you are using cms or already integrated temlplate) If you want to display many addresses you have to iterate through xml nodes print console.log(data); just after function(data, status){ .... to see the xml document returned ... If there is no places with the entered address, same thing you can guess it by reading the xml returned. thanks for reading !