用openlayers搜索地址

Chr*_*iso 6 geocoding openlayers-3

我有一个 PHP 项目,我正在使用 openlayers 制作地图,但我需要通过传递地址列表来定位书签,它必须是一个免费的地理编码器,因为有很多地址。非常感谢。

raf*_*226 7

要免费对您的地点地址进行地理编码,请使用 nominatim.openstreetmap.org 地理编码器和 jquery ajax,如下所示:

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

您将收到一个美味的 json 对象:

\n\n
address: {\n    city: "Bordeaux"\n    country: "France"\n    country_code: "fr"\n    county: "Bordeaux"\n    house_number: "22"\n    postcode: "33000"\n    road: "Rue Mouneyra"\n    state: "Nouvelle-Aquitaine"\n    suburb: "Saint-Augustin - Tauzin - Alphonse Dupeux"\n}\nboundingbox:["44.8341251", "44.8342251", "-0.581869", "-0.581769"]\nclass: "place"\ndisplay_name: "22, Rue Mouneyra, Saint-Augustin - Tauzin - Alphonse Dupeux, Bordeaux, Gironde, Nouvelle-Aquitaine, France m\xc3\xa9tropolitaine, 33000, France"\nimportance: 0.411\nlat: "44.8341751"\nlicence: "Data \xc2\xa9 OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright"\nlon: "-0.581819"\nosm_id: "2542169758"\nosm_type: "node"\nplace_id: "26453710"\ntype: "house"\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后,您可以循环对多个地点进行地理编码。

\n\n

干杯

\n

  • 是的,如果您发出太多请求,您将被禁止,因此在循环中您必须插入超时或延迟。 (2认同)

Svi*_*ica 0

你可以使用这样的东西:

  1. 搜索栏

    • 搜索图层中的要素
    • 在地图上搜索地点
  2. 搜索功能

享受 :)