您的位置:首页 > 运维架构

OpenStreetMap输入地址进行自动定位

2017-09-29 11:04 393 查看
在做GIS开发的时候,常常需要输入地名,地图自动定位到当前的地方,因为百度地图和谷歌地图中有类似的功能,但是在公司开发的时候,底图却没有百度地图和谷歌地图,所以就在官网上查看了OSM官网的文档,参考网址如下:

https://developer.mapquest.com/documentation/open/nominatim-search/search/

在地址栏输入http://nominatim.openstreetmap.org/search.php?format=json&zoom=18&addressdetails=1&q=角门西,服务器返回的数据如下:

[{"place_id":"21060783","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"node","osm_id":"2116038115","boundingbox":["39.8394284","39.8494284","116.3600357","116.3700357"],"lat":"39.8444284","lon":"116.3650357","display_name":"角门西, 马家堡西路, 新宫村, 丰台区, 北京市, 中国","class":"railway","type":"station","importance":0.111,"icon":"http:\/\/nominatim.openstreetmap.org\/images\/mapicons\/transport_train_station2.p.20.png","address":{"station":"角门西","road":"马家堡西路","village":"新宫村","county":"丰台区","state":"北京市","country":"中国","country_code":"cn"}},{"place_id":"4722780","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"node","osm_id":"528934416","boundingbox":["39.8394351","39.8494351","116.3598644","116.3698644"],"lat":"39.8444351","lon":"116.3648644","display_name":"角门西, 嘉和路, 新宫村, 丰台区, 北京市, 中国","class":"railway","type":"station","importance":0.111,"icon":"http:\/\/nominatim.openstreetmap.org\/images\/mapicons\/transport_train_station2.p.20.png","address":{"station":"角门西","road":"嘉和路","village":"新宫村","county":"丰台区","state":"北京市","country":"中国","country_code":"cn"}}]。。。


在js文件的代码如下所示:

var place=$("li.search .search_txt").val();   //输入的地名

$.getJSON("http://nominatim.openstreetmap.org/search.php?",{"format":"json","zoom":18,"addressdetails":1,"q":place}, function(data) { 
    console.log(JSON.stringify(data));
});



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息