Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search address with openlayers

I have a project in PHP and I'm using openlayers for maps, but I need to locate bookmarks by passing a list of addresses, it has to be a free geocoder since there are many addresses. Thank you very much.

like image 682
Christian Enciso Avatar asked Dec 20 '17 16:12

Christian Enciso


1 Answers

For geocoding your place adress for free, use nominatim.openstreetmap.org geocoder with jquery ajax this way :

var data = {
    "format": "json",
    "addressdetails": 1,
    "q": "22 rue mouneyra bordeaux",
    "limit": 1
};
$.ajax({
  method: "GET",
  url: "https://nominatim.openstreetmap.org",
  data: data
})
.done(function( msg ) {
    console.log( msg );
});

You will receive a yummy json object :

address: {
    city: "Bordeaux"
    country: "France"
    country_code: "fr"
    county: "Bordeaux"
    house_number: "22"
    postcode: "33000"
    road: "Rue Mouneyra"
    state: "Nouvelle-Aquitaine"
    suburb: "Saint-Augustin - Tauzin - Alphonse Dupeux"
}
boundingbox:["44.8341251", "44.8342251", "-0.581869", "-0.581769"]
class: "place"
display_name: "22, Rue Mouneyra, Saint-Augustin - Tauzin - Alphonse Dupeux, Bordeaux, Gironde, Nouvelle-Aquitaine, France métropolitaine, 33000, France"
importance: 0.411
lat: "44.8341751"
licence: "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright"
lon: "-0.581819"
osm_id: "2542169758"
osm_type: "node"
place_id: "26453710"
type: "house"

You can then geocode multiple places in a loop.

Cheers

like image 169
rafa226 Avatar answered Oct 21 '22 01:10

rafa226