【发布时间】:2011-09-12 19:39:16
【问题描述】:
我刚刚开始使用 Google Places API (http://code.google.com/apis/maps/documentation/javascript/places.html),但我似乎无法获得正确的语法传入边界而不是 latLng 对象和半径。
在 API 文档中它说:
此方法接受具有以下字段的请求: 任一个: bounds,它必须是定义要搜索的矩形的 google.maps.LatLngBounds 对象;或者 位置和半径;前者采用 google.maps.LatLng 对象,半径采用简单整数,以米为单位表示圆的半径。
我的代码如下所示:
var bnds = map.getBounds();
console.log(bnds); // this returns a valid bounds object!
var req = {
bounds: bnds
};
var service = new google.maps.places.PlacesService(map);
service.search(req, callback);
当我运行该页面时,我从 Google 服务收到错误 Uncaught Error: Property bounds not specified。如果我将 req 对象更改为
var req = {
location: latlngobject,
radius: '500'
}
它工作正常。关于传递边界对象而不是纬度/经度/半径的正确语法的任何想法?
【问题讨论】:
-
还应该补充一点,我在提交
var req. . .location: bnds时遇到同样的错误 -
我收到“未指定物业位置”。仅在界内传球时。你有没有解决过这个问题?似乎是 API 中的一个错误。
标签: javascript google-maps-api-3