首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >V3 :搜索请求

V3 :搜索请求
EN

Stack Overflow用户
提问于 2011-06-07 12:52:36
回答 1查看 4.4K关注 0票数 0

调用搜索服务api时

代码语言:javascript
复制
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);

http://maps.google.com/.

  1. 有必要给出搜索区域的位置/半径吗?
  2. ,如果我想在整个世界搜索一个位置,而不是像谷歌在谷歌在google中那样搜索特定的区域,那该怎么办呢?

--更新--

正如@Trott所建议的,这是我更新的代码,但我在回调函数中得到了status = "ZERO_RESULTS“。

代码语言:javascript
复制
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]); 
    }
}

我做错什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-07 16:34:55

  1. search()的调用必须包含一个位置和一个半径,或者包含一个边界(作为LatLngBounds对象)。这是在http://code.google.com/apis/maps/documentation/javascript/places.html#place_search_requests.
  2. You上记录的,如果您指定一个覆盖整个世界的LatLngBnds,它会看到会发生什么。还没有尝试过,但如果成功的话,这应该可以搜索整个世界,而不一定会造成特定位置的偏差。

LatLngBounds被记录在http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds上。我想你会想做这样的事:

代码语言:javascript
复制
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);
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6265443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档