views:

144

answers:

2

I have a webpage that finds a store by postcode or name.

I have just released an update to it so that contact details display in an info window coming from the marker. Due to the small size of the info window, after centering to the marker, the map pans down until it can fit the marker and info window in leaving the marker near the bottom.

Wondering if there is an easy way to set this offset immediately so that the marker appears at the bottom of the map window and it doesn't have to pan?

Thanks.

A: 

Perhaps the auto-panning is caused by an internal addoverlay event handler. Have you tried handling the addoverlay event and returning false from it?

GEvent.addListener(map, "addoverlay", function() {
  return false;
});

where 'map' is the name of your GMap2 object.

gWiz
+1  A: 

You could center the map appropriately before you add the marker:

var someZoom = 13;
var center = new GLatLng(37.4419, -122.1419);
map.setCenter(center, someZoom);

The zoom is optional too. You can just leave the zoom on whatever it is:

map.setCenter(center);

If you would like to center on a particular pixel, instead of a lat/lng, then you can use this function to convert:

fromContainerPixelToLatLng(pixel:GPoint)

I feel like you should spend half an hour and review the docs: http://code.google.com/apis/maps/documentation/reference.html. I read the documentation extensively while working on my website: www.trailbehind.com

Andrew Johnson
Great idea, in the next update i'll do this. Thanks.
Nat Ryall