Hi Guys,
I’ve been practising with the google maps api and am getting quite frustrated.
I took an example from the google code playground and pasted it straight into an html file, no problem, works fine.
However, when I place that same code into an aspx file, it stops working.
The map itself loads fine, as does the controls, but when it get’s to actually trying to do the geocaching part (Having a user type in an address and have it display a pushpin on the map) it grinds to a halt.
Here’s my javascript in the head
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
geocoder = new GClientGeocoder();
}
}
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.openInfoWindowHtml(address);
}
}
);
}
}
Form for inputting an address to geocache:
<form action="#" onsubmit="showAddress(this.address.value); return false">
<p>
<input type="text" size="60" name="address" value="1600 Amphitheatre Pky, Mountain View, CA" />
<input type="submit" value="Go!" />
</p>
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</form>
Then just added the following to the body tag:
onload="initialize()" onunload="GUnload()"
Can anyone tell me why this isn’t working?
I’m guessing it’s completely down to the form and how ASP.NET handles it, but forms in ASP.NET (and asp.net itself) are new to me, so I’m sure it’s something simple.
If anyone could shed some light on this I’d very much appreciate it.