谷歌地图api v3如何按最近距离排名 [英] google maps api v3 how to rank by closest distance
问题描述
有谁知道如何使用这里提到的距离搜索选项排名?
https://developers.google.com/maps/documentation/javascript / places#place_search_requests
在请求选项中列出此项似乎不起作用。这是我的部分代码:
pre $ var $ request $ {
location:coords,
/ / radius:30000,
关键字:['puma,retail'],
类型:['store'],
rankBy:google.maps.places.RankBy.DISTANCE
};
service = new google.maps.places.PlacesService(map);
service.search(request,callback);
函数回调(结果,状态){
if(status == google.maps.places.PlacesServiceStatus.OK){
for(var i = 0; i< results.length; i ++){
createMarker(results [i]);
listResults(results [i]);
}
}
}
代码将定位并列出结果如果我包含半径,但结果未按距离按升序排列。 Google的文档说如果使用rankBy选项,则不需要半径。我错过了什么?
遇到同样的问题。
根据此来源: http://www.geocodezip.com/v3_GoogleEx_place-search。 html
我能够制定这样的查询:
var request = {
位置:gps,
类型:['food'],//您也可以在此替换关键字:'食物',(不含双引号)。
rankBy:google.maps.places.RankBy.DISTANCE,//注意这里没有引号,我犯了这个错误。
key:key
};
Var key是API密钥,它不是必需的,但会添加以备后用。 GPS是:
var gps = new google.maps.LatLng(location.lat,location.lon);
最后,我做了您所做的一切,只是我添加了一个地图的界限,而我不打算使用。为此,我做了:
var bounds = new google.maps.LatLngBounds();
Does anyone know how to use the rank by distance search option that is mentioned here? https://developers.google.com/maps/documentation/javascript/places#place_search_requests
Listing this in the request options doesn't seem to work. Here's my portion of code relative to this:
var request = {
location: coords,
//radius: 30000,
keyword: ['puma, retail'],
types: ['store'],
rankBy: google.maps.places.RankBy.DISTANCE
};
service = new google.maps.places.PlacesService(map);
service.search(request, callback);
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
listResults(results[i]);
}
}
}
Code will locate and list results if I include a radius, but the results aren't listed in ascending order by distance. Google's docs say a radius isn't necessary either if using the rankBy option. Am I missing something?
Was having the same problem. As per this source: http://www.geocodezip.com/v3_GoogleEx_place-search.html I was able to formulate the query as such:
var request = {
location: gps,
types: ['food'], //You can substitute "keyword: 'food'," (without double-quotes) here as well.
rankBy: google.maps.places.RankBy.DISTANCE, //Note there is no quotes here, I made that mistake.
key: key
};
Var key is API key which is not required but added for later use. GPS is:
var gps = new google.maps.LatLng(location.lat,location.lon);
Lastly, I did everything that you did except I added bounds to a map that I was not going to use. For that I did:
var bounds = new google.maps.LatLngBounds();
这篇关于谷歌地图api v3如何按最近距离排名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!