Geeks With Blogs

News



Add to Google

Tim Hibbard CEO for EnGraph software

Here is some javascript code that we use on Where's Tim. It will only recenter the map if the new point is out of the map view. We use this code on the AJAX refresh button.    

map.clearOverlays();    
var pointA = new GPoint(-95, 38);    
var bounds = map.getBoundsLatLng();    
if ((pointA.x > bounds.maxX) || (pointA.x < bounds.minX) || (pointA.y > bounds.maxY) || (pointA.y < bounds.minY))    
//only executes if pointA is out of the bounds of the map       
{   map.centerAtLatLng(pointA);   }    
var markerA = new GMarker(pointA);    
GEvent.addListener(markerA, "click", function() { markerA.openInfoWindowHtml("some text"); }); 
map.addOverlay(markerA);

 More Google Maps API Info

Technorati Tags: , ,

Posted on Thursday, September 15, 2005 12:16 PM EnGraph , .NET , GPS , Mapping , Where's Tim | Back to top


Comments on this post: Google Maps code - smart centering on map

# re: Google Maps code - smart centering on map
Requesting Gravatar...
Your Where's Tim site is very nice. I believe I'm going to replace the current member map on my site with a Google map based one.
Left by solid on Sep 15, 2005 12:25 PM

Your comment:
 (will show your gravatar)


Copyright © Tim Hibbard | Powered by: GeeksWithBlogs.net | Join free