var map = null; var geocoder = null; var localSearch = new GlocalSearch(); function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map_canvas")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); geocoder = new GClientGeocoder(); } } function showAddress(street, postcode) { var address = street + ', ' + postcode; initialize() if (geocoder) { geocoder.getLatLng( address, function(point) { if (!point) { usePointFromPostcode(postcode, address); } else { map.setCenter(point, 13); var marker = new GMarker(point); map.addOverlay(marker); marker.openInfoWindowHtml(address); } } ); } } function usePointFromPostcode(postcode, address) { localSearch.setSearchCompleteCallback(null, function() { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; var point = new GLatLng(resultLat,resultLng); map.setCenter(point, 13); var marker = new GMarker(point); map.addOverlay(marker); marker.openInfoWindowHtml(address); }else{ alert("Postcode not found!"); } }); localSearch.execute(postcode + ', UK'); } function usePointFromLatLong(x, y, address) { initialize() var resultLat = x; var resultLng = y; var point = new GLatLng(resultLat,resultLng); map.setCenter(point, 13); var marker = new GMarker(point); map.addOverlay(marker); marker.openInfoWindowHtml(address); }