Search address with openlayers
Asked Answered
E

2

8

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.

Eisenhower answered 20/12, 2017 at 16:53 Comment(0)
O
7

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

Overwhelming answered 15/11, 2018 at 14:52 Comment(2)
I was reading about nominatim and it looks like it's limited to 1 query per second, so that probably wouldn't help with geocoding a whole list of addresses.Charter
Yes and if you do too much requests, you will get banned, so in the loop you have to insert a timeout, or a delay.Overwhelming
J
0

You can use something like this :

  1. Search bar

    • search features in a layer
    • search places on the map
  2. Search features

Enjoy :)

Jestinejesting answered 2/1, 2018 at 14:0 Comment(1)
links are brokenSkyrocket

© 2022 - 2024 — McMap. All rights reserved.