更新时间:2022-10-15 16:59:05
我假设你在150个较小瓷砖的区域坐标之后?
map.getBounds()返回一个GLatLngBounds对象。这包括getSouthWest()和getNorthEast()方法。因此,从可见地图的左下角和右上角的纬度/经度值可以推导出150个较小区域的坐标:
因此,要为特定单元索引(x,y)实例化GLatLngBounds(sw?:GLatLng,ne?:GLatLng):
// bounds是map.getBounds()的结果
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));
I want to divide the map display area into a number of equal parts. For example: 10 parts horizontally and 15 parts vertically, resulting in 150 equal parts.
I do not know if Google Maps support such a thing...
map.getBounds()
return the total visible area;
so ,
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());
}
}
now the problem is tileBounds.isEmpty() returns TRUE !!
I cant able to find where I am missing something !! Any Help !!
I am assuming you are after the region coordinates for the 150 smaller tiles?
map.getBounds () returns a GLatLngBounds object. This includes getSouthWest () and getNorthEast () methods. So from the latitude/longitude values for the bottom left and top right hand corners of the visible map you could derive the coordinates of the set of 150 smaller regions:
So to instantiate a GLatLngBounds(sw?:GLatLng, ne?:GLatLng) for a particular cell index (x, y):
// 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));