谷歌地图自动完成获取LatLngBound?

时间:2015-01-19 14:55:36

标签: google-maps-api-3 google-places-api

如何通过自动完成功能获取场所中的latlngbound?

获取纬度我使用以下代码

var place = places.getPlace();
var latitude = place.geometry.location.lat();

但是,当我尝试使用代码获取latlngbounds

时,它无效
// northeast is undefined
var latlngbounds = place.geometry.bounds.northeast.lat();

// undefined
var latlngbounds = place.geometry.bounds;

1 个答案:

答案 0 :(得分:1)

PlaceGeometry还包含一个建议的视口,它是一个google.maps.LatLngBounds对象。 (它的名字是视口,但不是边界)

Properties  Type    Description
location    LatLng  The Place's position.
viewport    LatLngBounds    The preferred viewport when displaying this Place on a map. This property will be null if the preferred viewport for the Place is not known.
var place = places.getPlace();
var latitude = place.geometry.location.lat();
var bounds = place.geometry.viewport;