Google Maps getBounds doesn't seem to be returning the correct bounds.
I'm implementing some boundary based clustering on the server end of markers to display on my google maps. What I'm doing is that I have a function that is called everytime the map is moves or panned or zoomed which takes the bound of the map and makes an ajax call which in turn the server side script runs a simple sql query to retrieve the markers and clusters them. SO far teh clustering part is working nicely however sometimes the getBounds doesn't seem to be sending the correct boundaries I feel.

Like I may pan a map a bit on the side and regions which used to have markers now all of a sudden don't have markers and the map is blank. I checked the sql query and from the query itself it shows an outrageously different bounds than what would be expected.

Take a look at the regions below:
![Orginal WitH Markers][1]
![No markers][2]

The first one shows all the markers.

The one following however has just moved a bit to the top and left but half the region is the same as in the previous picture however there are no markers at all. I have isolated the issue to be with the getBounds function of the maps.

This is my javascript code which gets the bounds and makes the call:

    var bounds = map.getBounds();
    var southWest = bounds.getSouthWest();
    	
    var northEast = bounds.getNorthEast();
    var data = {ne:northEast.toUrlValue(), sw:southWest.toUrlValue(), zoom:map.getZoom()};
    //something getting messed up in the code above this point
    	
    $.ajax({
    	type: "POST",
    	url: 'maps/get-markers',
    	data: {object:$.toJSON(data)},
    	dataType: 'json',
    	
    	success: function(response) {
    		//code to add markers
    	}
    });

On my server side code this is the php used to get the items based upon the coordinates:


    $data =  Zend_Json::decode(stripslashes($this->_request->getParam('object')));
    
    //retrieve the variables from the GET vars
    list($nelat, $nelng) = explode(',', $data['ne']);
    list($swlat, $swlng) = explode(',',$data['sw']);
    
    //clean the data
    $nelng 	= 	(float)$nelng;
    $swlng 	= 	(float)$swlng;
    $nelat 	= 	(float)$nelat;
    $swlat 	= 	(float)$swlat;
    
    $ubound = $swlng > $nelng ? $swlng : $nelng;
    $lbound = $swlng > $nelng ? $nelng : $swlng;
    				
    $sql = 'SELECT `a`.* FROM `locations` AS `a` WHERE (a.`longitude` > $lbound) AND (a.`longitude` < $ubound) AND';
    
    $ubound = $swlat > $nelat ? $swlat : $nelat;
    $lbound = $swlat > $nelat ? $nelat : $swlat;
    
    
    $sql .= ' (a.`latitude` >= $lbound) AND (a.`latitude` <= $ubound)';

I'm suspecting its the getbounds function in the javascript but need to fix it asap. Any ideas please :(

  [1]: http://i31.tinypic.com/xds4t0.jpg
  [2]: http://i31.tinypic.com/2r22ez4.jpg

Google Maps getBounds doesn't seem to be returning the correct bounds.
===

I'm implementing some boundary based clustering on the server end of markers to display on my google maps. What I'm doing is that I have a function that is called everytime the map is moves or panned or zoomed which takes the bound of the map and makes an ajax call which in turn the server side script runs a simple sql query to retrieve the markers and clusters them. SO far teh clustering part is working nicely however sometimes the getBounds doesn't seem to be sending the correct boundaries I feel.

Like I may pan a map a bit on the side and regions which used to have markers now all of a sudden don't have markers and the map is blank. I checked the sql query and from the query itself it shows an outrageously different bounds than what would be expected.

Take a look at the regions below:
![Orginal WitH Markers][1]
![No markers][2]

The first one shows all the markers.

The one following however has just moved a bit to the top and left but half the region is the same as in the previous picture however there are no markers at all. I have isolated the issue to be with the getBounds function of the maps.

This is my javascript code which gets the bounds and makes the call:

    var bounds = map.getBounds();
    var southWest = bounds.getSouthWest();
    	
    var northEast = bounds.getNorthEast();
    var data = {ne:northEast.toUrlValue(), sw:southWest.toUrlValue(), zoom:map.getZoom()};
    //something getting messed up in the code above this point
    	
    $.ajax({
    	type: "POST",
    	url: 'maps/get-markers',
    	data: {object:$.toJSON(data)},
    	dataType: 'json',
    	
    	success: function(response) {
    		//code to add markers
    	}
    });

On my server side code this is the php used to get the items based upon the coordinates:


    $data =  Zend_Json::decode(stripslashes($this->_request->getParam('object')));
    
    //retrieve the variables from the GET vars
    list($nelat, $nelng) = explode(',', $data['ne']);
    list($swlat, $swlng) = explode(',',$data['sw']);
    
    //clean the data
    $nelng 	= 	(float)$nelng;
    $swlng 	= 	(float)$swlng;
    $nelat 	= 	(float)$nelat;
    $swlat 	= 	(float)$swlat;
    
    $ubound = $swlng > $nelng ? $swlng : $nelng;
    $lbound = $swlng > $nelng ? $nelng : $swlng;
    				
    $sql = 'SELECT `a`.* FROM `locations` AS `a` WHERE (a.`longitude` > $lbound) AND (a.`longitude` < $ubound) AND';
    
    $ubound = $swlat > $nelat ? $swlat : $nelat;
    $lbound = $swlat > $nelat ? $nelat : $swlat;
    
    
    $sql .= ' (a.`latitude` >= $lbound) AND (a.`latitude` <= $ubound)';

I'm suspecting its the getbounds function in the javascript but need to fix it asap. Any ideas please :(

  [1]: http://i31.tinypic.com/xds4t0.jpg
  [2]: http://i31.tinypic.com/2r22ez4.jpg
