thewhistler1
Technical User
I am trying to get a google map on my site but I cant figure part of it out. I know very little about javascript, Im sure this is a simple fix. The code below starts with one map and has a box to go to another location. What I would like is for the page to come up to whatever address that I have listed in a variable in the code of that page rather then having to click a button to take you to that location. Thanks
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps API Example: Simple Geocoding</title>
<script src="[URL unfurl="true"]http://maps.google.com/maps?file=api&v=2.x&key=somekey"[/URL] type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
var address = "some address";
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.closeInfoWindowHtml(address);
}
}
);
}
}
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
geocoder = new GClientGeocoder();
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<form action="#" onsubmit="showAddress(this.address.value); return false">
<p>
<input type="text" size="60" name="address" value="some address" />
<input type="submit" value="Go!" />
</p>
<div id="map_canvas" style="width: 500px; height: 400px"></div>
</form>
</body>
</html>