tags:

views:

542

answers:

1

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 !!

+1  A: 

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));
Cannonade
Thanks a lot, I am almost there.But confuse on How to get the coordinates for a particular cell and how to get it's offset in x and y ?
openidsujoy
I'll update my answer with that stuff ...
Cannonade
just a minute thing ,tileHeight and tileWidth I will get bye,tileWidth = (bounds.getNorthEast.lng() - bounds.getSouthWest.lng()) / 10;tileHeight = (bounds.getNorthEast.lat() - bounds.getSouthWest.lat()) / 15;but how to retrieve x and y to get northLat or westLng value ?
openidsujoy
i.e. how to get particular cells x, y point ? or am I missing something ?
openidsujoy
I am using x and y just a logical index into the array of cells, so the top left cell is x=0,y0, bottom right cell is x=9, y=14, etc ... so you could build a nested for loop to generate the region for each tile.
Cannonade
I cannot able to use the 'tileBounds' which I am getting,tileBounds.isEmpty() returns TURE , I am accepting a FALSE value for tileBounds.isEmpty() call. any idea.
openidsujoy
any Help on this , actually what want wrong in implementation.
openidsujoy