Can I zoom in on a google map marker

Nick_SD
Nick_SD used Ask the Experts™
on
I have a page which loads up 20 markers into a google map
http://offers.ftvdirect.co.uk/list.asp

I would like to zoom in on the map when the user clicks on the left hand side markers

has anybody got any code which will let me do this

thanks

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sudaraka WijesingheWeb Application Programmer

Commented:
I don't have any sample code. But I believe this can be done with GMap2.setCenter method.

http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GMap2.setCenter

Author

Commented:
I was really wanting the map marker to show the bubble and centre on it when selecting the corresponding letter
Can this be done  ?
Sudaraka WijesingheWeb Application Programmer

Commented:
I'm speaking only on theory here, I haven't tried this myself. I think its possible with setCenter.
I assume you already know the geo location of the pointer, so simply call setCenter with that position and the zoom level you want.
map.setCenter(new GLatLng(lat, lon), 10);

Open in new window

leakim971Multitechnician
Top Expert 2014

Commented:

Author

Commented:
the mapcentering appears to get rid of existing markers on the map
and simply create a new one.

Author

Commented:
@leakim971 the markers are off the map , the sample you sent was on map (i think)
leakim971Multitechnician
Top Expert 2014

Commented:
line 347 to 349 replace :
                        GEvent.addListener(marker, 'click', function () {
                            marker.openInfoWindowHtml(locdesc);
                        }); 

Open in new window

by :
				GEvent.addListener(marker, 'click', function () {
					map.setCenter(marker.getLatLng(), 14); // 14 is the zoom
					marker.openInfoWindowHtml(locdesc);
				}); 

Open in new window

leakim971-486572.flv

Author

Commented:
thanks but this is "in map clicking" ,it  looks great but need this to happen from a click outside the map take a look at this link http://offers.ftvdirect.co.uk/list.asp

you will see what i mean , links on the left outside the map.

im sorry if im missing the obvious here. If I can call the function from outside the map can you show me what im missing

leakim971Multitechnician
Top Expert 2014

Commented:
>a look at this link http://offers.ftvdirect.co.uk/list.asp

yes, but please confirm it don't work

Author

Commented:


yes when the user click on "A" inside the map it centers and shows the box, (thanks for that)

my initial request was when the user clicks on the left hand side markers (out of map)
the map zooms into that marker

can this be done or am i missing the point?

Multitechnician
Top Expert 2014
Commented:
put :
			function showmap(lng,lat)
			{
				map.setCenter(new GLatLng(lng, lat), 16);
			}

Open in new window

outside of       function initialize() {

and replace :
	function initialize() {

		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById('map_canvas'));

Open in new window

by :
var map;
	function initialize() {

		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById('map_canvas'));

Open in new window

Author

Commented:
great thanks

yes thats superb , anyway to popup the info box on the marker or am i asking too much
leakim971Multitechnician
Top Expert 2014

Commented:
not with your current code because your sidebar and markers are currently in different world
Check this example to see if it help you rebuild your page :
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27107049.html?cid=1131#a35999654

Author

Commented:
ok thanks for that, Im not sure why on earth they make this so complicated

Nick

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial