我正在尝试使用places库来使用LatLngBounds类在两个坐标之间显示标记。如果我在地方搜索请求中注释出starbucks的name属性,我可以看到一些标记。有人请指导我以下内容:
1)目前我看到的标记位于两个坐标的中间,并且沿着边界不均匀分布,我假设它创建了一个矩形,您必须在其中看到它们。我认为标记只是为中心计算的。
2)当我提供属性'name'和值“starbucks”时,我在地图上看不到任何标记。
我认为我的bounds
对象很好,因为当我调试时,我能够看到里面的西北和西南坐标。坐标是
有人可以指导我出错的地方。
function useCordinates(){
...
var defaultBounds = new google.maps.LatLngBounds();
var places = [];
places.push(new google.maps.LatLng(latLongSrc[0],latLongSrc[1]));
places.push(new google.maps.LatLng(latLongDest[0],latLongDest[1]));
defaultBounds.extend(places[0]);
defaultBounds.extend(places[1]);
//var center = defaultBounds.getCenter();
//defaultBounds.contains(center);
var request = {
//attribute to be commented
name:"starbucks",
bounds: defaultBounds,
types:['establishment']
};
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++) {
var place = results[i];
createMarker(results[i]);
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
}
答案 0 :(得分:2)
你的界限是一个非常窄的矩形,在洛杉矶和亚特兰大之间延伸(不是我想你想要的):
http://www.geocodezip.com/v3_GoogleEx_place-search_starbucks.html
针对整个国家/地区的地方请求有问题,您只能得到20个结果,看起来您可能是正确的,他们以边界为中心,并且似乎没有任何“真正的”星巴克足够接近那里被发现:
http://www.geocodezip.com/v3_GoogleEx_place-search_starbucks2.html
如果你在华盛顿州西雅图搜索,你会得到一些:
http://www.geocodezip.com/v3_GoogleEx_place-search_starbucks3.html