Reputation: 687
I've implemented GMAPS V3 and having trouble centering up the marker in #map. If you click on one of the locations in the above link, it goes to the location and does the zoom as it should, however, it doesn't center it up.
How can I have it centered once the user clicks on the location in the address list?
Thanks!
Upvotes: 0
Views: 9119
Reputation: 6242
in your click event listener
google.maps.event.addListener(marker, "click", function() {
add
map.setCenter(marker.getPosition())
see a working example here: http://jsfiddle.net/RASG/vA4eQ/
(drag the marker to re-center)
Upvotes: 2
Reputation: 6147
Update your code like
var myLatLng = new google.maps.LatLng(c_lat,c_lng);
var myOptions = {
zoom: 2,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
Upvotes: 0
Reputation: 5282
You are centering map OK buth upon opening infowindow iz pans so that it is visible. IMHO you have 2 oprions: 1. after showing infowindow pan to marker position, buth there is possibility that infowindow will be out of viewport. 2. Use Smartinfowindow control
Include this JS into youre page
http://gmaps-samples-v3.googlecode.com/svn/trunk/smartinfowindow/js/smartinfowindow.js
Try to understand source of thise DEMO page (very simple).
http://gmaps-samples-v3.googlecode.com/svn/trunk/smartinfowindow/smartinfowindow.html
And good luck.
Upvotes: 0
Reputation: 1500
map.setCenter(marker.getPosition());
I'd also consider making your map a little larger as the info box will be out of view when the map is centered on the marker.
Upvotes: 0