我正在使用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時刻的地獄!感謝您指出了這一點。 –