我怎样才能将Google地图显示分成相同数量的部分? [英] How might I divide a Google Maps display into an equal number of parts?

查看:103
本文介绍了我怎样才能将Google地图显示分成相同数量的部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将地图显示区域分成许多相等的部分。例如:横向10个部分和纵向15个部分,导致150个相等部分。



我不知道Google地图是否支持这样的事情...



map.getBounds()返回总可见区域;
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; (var y = 0; y <2; y ++)
{

为(var x = 0; x <10; x ++)
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());



code
$ b现在问题是tileBounds.isEmpty ()返回TRUE!



我无法找到我错过的东西!任何帮助!!

解决方案

我假设你在150个较小瓷砖的区域坐标之后?



map.getBounds()返回一个GLatLngBounds对象。这包括getSouthWest()和getNorthEast()方法。因此,从可见地图的左下角和右上角的纬度/经度值可以推导出150个较小区域的坐标:


  • 将宽度(getNorthEast()的经度 - getSouthWest()的经度)除以15,以确定宽度。 分隔高度(getNorthEast()的纬度 - getSouthWest()的纬度除以10,以确定瓷砖高度。
  • 根据x和y的偏移量乘以宽度和高度,计算特定单元格的坐标。
  • >


因此,要为特定单元索引(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:

  • Divide the width (longitude of getNorthEast () - longitude of getSouthWest ()) by 15, to determine tile width.
  • Divide the height (latitude of getNorthEast () - latitude of getSouthWest ()) by 10, to determine tile height.
  • calculate the coordinates for a particular cell based on it's offset in x and y multiplied by the width and height.

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));

这篇关于我怎样才能将Google地图显示分成相同数量的部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆