我想将地图显示区域划分为多个相等的部分。例如:水平10个部分,垂直15个部分,产生150个相等的部分。
我不知道谷歌地图是否支持这样的事情......
map.getBounds()
返回总可见区域;
所以,
var bounds = map.getBounds();
alert("main: "+bounds.isEmpty());
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var tileWidth = (northEast.lng() - southWest.lng()) / 10;
var tileHeight = (northEast.lat() - southWest.lat()) / 2;
for (var x=0; x < 10 ; x++)
{
for (var y=0; y < 2 ; y++)
{
var northLat = bounds.getNorthEast().lat () + (tileHeight * y);
var westLng = bounds.getSouthWest().lng () + (tileWidth * x);
var southLat = northLat + tileHeight;
var eastLng = westLng + tileHeight;
var tileBounds = new GLatLngBounds(new GLatLng(southLat, westLng), new GLatLng(northLat, eastLng));
alert(tileBounds.isEmpty());
}
}
现在问题是tileBounds.isEmpty()返回TRUE !!
我无法找到我遗失的地方!任何帮助!!
答案 0 :(得分:1)
我假设你是在150个较小的瓷砖的区域坐标之后?
map.getBounds()返回GLatLngBounds对象。这包括getSouthWest()和getNorthEast()方法。因此,根据可见地图左下角和右上角的纬度/经度值,您可以得出150个较小区域的坐标:
因此要为特定的单元格索引(x,y)实例化GLatLngBounds(sw?:GLatLng,ne?:GLatLng):
// bounds is the map.getBounds () result
northLat = bounds.getNorthEast().lat () + (tileHeight * y);
westLng = bounds.getSouthWest().lng () + (tileWidth * x);
southLat = northLat + tileHeight;
eastLng = westLng + tileHeight;
tileBounds = new GLatLngBounds (new GLatLng (southLat, westLng), new GLatLng (northLat, eastLng));