Tim Hibbard

CEO for EnGraph software
posts - 629 , comments - 1693 , trackbacks - 459

My Links

News



Add to Google

Twitter












Tag Cloud

Article Categories

Archives

Post Categories

Image Galleries

EnGraph Blogs

Links

Other

Roll

Google Maps code - smart centering on map

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: , ,

Print | posted on Thursday, September 15, 2005 12:16 PM | Filed Under [ EnGraph .NET GPS Mapping Where's Tim ]

Feedback

Gravatar

# re: Google Maps code - smart centering on map

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.
9/15/2005 12:25 PM | solid
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: