0
我想獲得API要求的谷歌地圖的四個角落。使用谷歌地圖獲取地圖角座標 - javascript api
swLat swLng neLat neLng
我有以下的代碼,但這些都是返回的對象和林不知道如果這是它甚至要求。這些配對(一旦他們返回correctyl)NE - >?由於
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
google.maps.event.addListenerOnce(map, 'bounds_changed', function() {
var rectangle = new google.maps.Rectangle({
bounds: map.getBounds()
})
var bounds = rectangle.getBounds();
var NE = bounds.getNorthEast();
var NEmark = new google.maps.Marker({
map: map,
position: NE,
title: "NE"
});
var SW = bounds.getSouthWest();
var SWmark = new google.maps.Marker({
map: map,
position: SW,
title: "SW"
});
// North West
var NW = new google.maps.LatLng(NE.lat(), SW.lng());
var NWmark = new google.maps.Marker({
map: map,
position: NW,
title: "NW"
});
// South East
var SE = new google.maps.LatLng(SW.lat(), NE.lng());
var SEmark = new google.maps.Marker({
map: map,
position: SE,
title: "SE"
});
$scope.NE = NE
$scope.NW = NW
$scope.SW = SW
$scope.SE = SE
var polygon = new google.maps.Polygon({
map: map,
paths: [
[NE, NW, SW, SE]
]
});
map.setZoom(map.getZoom() - 1);
});
console.log("SE" + $scope.SE) //all undefined
console.log("NW" + $scope.NW)
console.log("SW" + $scope.SW)
console.log("NE" + $scope.NE)