我正在做一个项目,要求我在距离用户邮政编码(邮政编码)5英里的参数范围内找到最近的酒吧(酒吧)。
有什么方法可以用Google来接收数组中的数据,循环遍历数据,然后根据lat建立标记,然后从数据中长期接收到数据呢?
发布于 2015-07-03 13:03:53
您可以在这里找到关于Google的特定特性的信息:https://developers.google.com/places/webservice/search
此web服务允许您在指定位置和搜索半径的同时使用关键字进行搜索,并返回与json或xml文档中的这些参数匹配的位置列表。
您的示例如下所示:
https://maps.googleapis.com/maps/api/place/textsearch/json?key=your_api_key&query="bar"&location=lat,lon&radius=8000
你需要替换
your_api_key
应用程序(您需要一个才能使用他们的web服务)lat,lon
,如用户agmangas建议的,您可以在地理编码web服务中找到它。8000
有实际搜索半径,以米为单位(5英里约8公里)。发布于 2015-07-03 13:05:38
首先,您必须从用户的邮政编码中获取纬度和经度,这可以使用地理编码服务实现。
一旦你有了这个,我会说你需要使用地点图书馆 (免责声明:我从未真正使用过它)。
在附近的搜索部分下面有一个代码示例,我认为它或多或少会满足您的需要(您需要稍微修改一下):
var map;
var service;
var infowindow;
function initialize() {
// Replace with the latitude and longitude
// you got in a Geocoding Service request
var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);
map = new google.maps.Map(document.getElementById('map'), {
center: pyrmont,
zoom: 15
});
// Replace the place type you need ("bar")
// Replace the radius (5 miles)
var request = {
location: pyrmont,
radius: '500',
types: ['store']
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
createMarker(results[i]);
}
}
}
https://stackoverflow.com/questions/31207168
复制相似问题