I am trying to do a google map - and I'm fine with it... what I'm having problems with is controlling the map from links on the page. I want something to happen to the map when you mouseover a link on the page. I have the code in my website set up like this: <a href="#" onmouseover="doSomething();" onmouseout="return false;">test</a> Code (markup): And I have the map script (which is all working corectly) set up like this... my function is near the bottom... what am I doing wrong? I get the error: function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); //map.addControl(new GMapTypeControl()); //map.addControl(new GSmallZoomControl()); map.setCenter(new GLatLng(52.28164125024719, -1.3841164112091064), 6); GDownloadUrl("depotlist.json", function( data, responseCode ){ parseJson(data); }); map.setMapType(G_NORMAL_MAP); map.disableDragging(); function makeIcon (image) { var icon = new GIcon(); icon.image = image; icon.iconSize = new GSize(27, 27); icon.shadowSize = new GSize(24, 16); icon.iconAnchor = new GPoint(13, 13); icon.infoShadowAnchor = new GPoint(0, 0); icon.infoWindowAnchor = new GPoint(8, 1); return icon; } function createMarker(input) { var marker = new PdMarker(input.point, makeIcon(input.icon) ); marker.setTooltip( input.depotName ); GEvent.addListener(marker, "click", function() { if (marker.getMouseOutEnabled()) { marker.setMouseOutEnabled(false); map.setCenter((input.point), 17); map.setMapType(G_SATELLITE_MAP); document.getElementById('address').innerHTML = (input.address); } else { marker.setMouseOutEnabled(true); map.setCenter(new GLatLng(52.28164125024719, -1.3841164112091064), 6); map.setMapType(G_NORMAL_MAP); document.getElementById('address').innerHTML = (' '); } }); function doSomething() { map.setMapType(G_SATELLITE_MAP); } return marker; } function parseJson (doc) { var jsonData = eval("(" + doc + ")"); for (var i = 0; i< jsonData.depots.length; i++) { var marker = createMarker(jsonData.depots[i]); map.addOverlay(marker); } } } } window.onload = initialize; window.onunload = GUnload; Code (markup):
Try: var map; function doSomething() { map.setMapType(G_SATELLITE_MAP); } function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map_canvas")); //map.addControl(new GMapTypeControl()); //map.addControl(new GSmallZoomControl()); map.setCenter(new GLatLng(52.28164125024719, -1.3841164112091064), 6); GDownloadUrl("depotlist.json", function( data, responseCode ){ parseJson(data); }); map.setMapType(G_NORMAL_MAP); map.disableDragging(); function makeIcon (image) { var icon = new GIcon(); icon.image = image; icon.iconSize = new GSize(27, 27); icon.shadowSize = new GSize(24, 16); icon.iconAnchor = new GPoint(13, 13); icon.infoShadowAnchor = new GPoint(0, 0); icon.infoWindowAnchor = new GPoint(8, 1); return icon; } function createMarker(input) { var marker = new PdMarker(input.point, makeIcon(input.icon) ); marker.setTooltip( input.depotName ); GEvent.addListener(marker, "click", function() { if (marker.getMouseOutEnabled()) { marker.setMouseOutEnabled(false); map.setCenter((input.point), 17); map.setMapType(G_SATELLITE_MAP); document.getElementById('address').innerHTML = (input.address); } else { marker.setMouseOutEnabled(true); map.setCenter(new GLatLng(52.28164125024719, -1.3841164112091064), 6); map.setMapType(G_NORMAL_MAP); document.getElementById('address').innerHTML = (' '); } }); return marker; } function parseJson (doc) { var jsonData = eval("(" + doc + ")"); for (var i = 0; i< jsonData.depots.length; i++) { var marker = createMarker(jsonData.depots[i]); map.addOverlay(marker); } } } } window.onload = initialize; window.onunload = GUnload; PHP: Where did you get this code from?
Ah! It makes sense when I see it written like that! Thank you, that's sorted all my problems. I wrote the code with the aid of the PDMarker user guide website - why?