Google Maps Javascript API第3版:搜索请求 [英] Google Maps Javascript API V3 : Search Requests

查看:74
本文介绍了Google Maps Javascript API第3版:搜索请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用搜索服务api时

var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);
var request = { location: pyrmont, radius: '500', types: ['store'] };
service = new google.maps.places.PlacesService(map);
service.search(request, callback);

  1. 是否有必要提供搜索区域的位置/半径?
  2. 如果我想在全球范围内而不是像google这样在指定区域中搜索位置,该怎么办? http://maps .google.com/.

---更新---

这是@Trott建议的这是我的更新代码,但我在回调函数中获得status ="ZERO_RESULTS".

This is my updated code as @Trott advised but i am getting status = "ZERO_RESULTS" in my callback function.

var keyword='search placename';
var request = { name : keyword,
bounds : new google.maps.LatLngBounds(
google.maps.LatLng(-89.999999,-179.999999),
google.maps.LatLng(89.999999,179.999999)
)};
service = new google.maps.places.PlacesService(map);
service.search(request, callback);

function callback(results, status)
{
    console.log("status="+status);
    if ( status == google.maps.places.PlacesServiceStatus.OK)
    {
        for (var i = 0; i < results.length; i++)
        console.log(results[i]); 
    }
}

我做错了什么?

推荐答案

  1. search()的调用必须包含位置和半径,或者包含边界(作为LatLngBounds对象).记录在 http://code.google.com/apis /maps/documentation/javascript/places.html#place_search_requests .

  1. Calls to search() must contain either a location and a radius, or else a bounds (as a LatLngBounds object). This is documented at http://code.google.com/apis/maps/documentation/javascript/places.html#place_search_requests.

如果指定一个覆盖整个世界的LatLngBnds,您会看到会发生什么.还没有尝试过,但是如果可行,那应该具有搜索整个世界而不必偏向特定位置的效果.

You could see what happens if you specify a LatLngBnds that covers the entire world. Haven't tried it, but if it worked, that should have the effect of searching the whole world without necessarily biasing a particular location.

LatLngBounds已记录在 http://code.google上. com/apis/maps/documentation/javascript/reference.html#LatLngBounds .我想您想做这样的事情:

LatLngBounds is documented at http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds. I think you'd want to do something like this:

var sw = new google.maps.LatLng(-89.999999,-179.999999);
var ne = new google.maps.LatLng(89.999999,179.999999);
var bounds = new google.maps.LatLngBounds(sw,ne);

这篇关于Google Maps Javascript API第3版:搜索请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆