I have the following code ( I have also attached a aspx file) which is very simple and has a map which initializes to the users location, and the user can choose a location from the dropdown to show on the map. The initialization works fine, but when I debug the code in firebug, I can see that geocoder.geocode is returning empty string for status. Does the call to api fail, or I am not sure what is happening. Please help. I have spent two days on this. Thanks.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
//center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
// Try W3C Geolocation (Preferred)
if(navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeolocation(browserSupportFlag);
});
// Try Google Gears Geolocation
} else if (google.gears) {
browserSupportFlag = true;
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeoLocation(browserSupportFlag);
});
// Browser doesn't support Geolocation
} else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
function handleNoGeolocation(errorFlag) {
if (errorFlag == true) {
alert("Geolocation service failed.");
initialLocation = newyork;
} else {
alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
initialLocation = siberia;
}
map.setCenter(initialLocation);
}
}
var map;
var geocoder;
function codeAddress(sAddress)
{
geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': sAddress},function(results, status){});
}
function showAddress(sAddress){
codeAddress(sAddress);
if ( status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
}
}
function findAddress() {
if (document.getElementById("ddlCompanies") == null )
return false;
else{
var ddlAddress = document.getElementById("ddlCompanies");
var ddlAddressIndex = ddlAddress.selectedIndex;
var ddlAddressValue = ddlAddressIndex.value;
var address = ddlAddress.options[ddlAddress.selectedIndex].value;
showAddress(address);
return false;
}
}