I read Imar's book - beginning Asp.net 3.5. It is a great book.
I then started building a website but i'm having issues with google maps javascript. I was trying out some sample code from Google's training but i keep getting the error on firebug - "google.maps.Geocoder is not a constructor"
for the line: geocoder = new google.maps.Geocoder();
I searched for the error online and found a few posting recommending - google.setOnLoadCallback() - to be used. But when i used that i seem to be getting more errors.
Below is the code for the entire page. Please let me know what's causing the error.
Thank you!
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Maps2.aspx.cs" Inherits="Trial_Maps2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&
key=ABQIAAAAJufm5IbqOx3oHcWCrkcpPZyfNiLPHlJijQMANFPQ"
type="text/javascript"></script>
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 320px; height: 480px;"></div>
<div>
<input id="address" type="text" value="Sydney, NSW"/>
<input type="button" value="Encode" onclick="codeAddress()"/>
</div>
</body>
</html>