我正在使用google maps JavaScript API,并且当前我正在尝试创建LatLngBounds对象,以便我可以将其应用于基于位置的Google地图在一个数组中。尝试从有效LatLng对象创建LatLngBounds对象时出错
我发现西南部和东北部最高分,创造从他们经纬度对象,然后试图用这些来创建对象LatLangBounds:
centerMap: function(){
var lowestLatitude = this.locations.reduce(function (carry, nextLocation, index){
return carry < nextLocation.position.lat && carry !== null ? carry : nextLocation.position.lat;
}, null);
var lowestLongitude = this.locations.reduce(function (carry, nextLocation, index){
return carry < nextLocation.position.lng && carry !== null ? carry : nextLocation.position.lng;
}, null);
var highestLatitude = this.locations.reduce(function (carry, nextLocation, index){
return carry > nextLocation.position.lng && carry !== null ? carry : nextLocation.position.lat;
}, null);
var highestLongitude = this.locations.reduce(function (carry, nextLocation, index){
return carry > nextLocation.position.lng && carry !== null ? carry : nextLocation.position.lng;
}, null);
debugger;
var southWest = new google.maps.LatLng({ lat: lowestLatitude, lng: lowestLongitude});
var northEast = new google.maps.LatLng({ lat: highestLatitude, lng: highestLongitude});
var bounds = new google.maps.LatLngBounds({sw: southWest, ne: northEast});
this.map.fitBounds(bounds);
}
我遇到的错误是,当我创建LatLngBounds实例。我得到的错误:
Uncaught InvalidValueError: not a LatLng or LatLngLiteral: in property lat: not a number
的事情是,有没有错误创造了西南和东北的经纬度情况下,如此看来奇怪的是,试图创建两种有效的经纬度对象范围将抛出一个错误。
我缺少什么导致了此错误?
Aww你对我来说太快了! +1! – Oliver
那么这是一个facepalm时刻的地狱!感谢您指出了这一点。 –