Michael Laird
unread,Jan 17, 2012, 2:27:32 PM1/17/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-map...@googlegroups.com
I geolocate the user via the browser, display a map and populate country, state and city input boxes from the Google geocode object. When the user enters a specific address, I want to revise and re-display the map with a new mapCenter, more zoom, and eventually a marker and infowindow. Despite many hours of research and trials, I can't get the map to revise. As best I can tell from the Developer Tool in Chrome, the code fails/ceases in the geocoder.geocode line of the blur function, set out in bold below. Nothing below it has ever executed. This is localhost development, but here is relevant code.
var map, geocoder, marker, infowindow; //global variables
function initializeMap() {
//initialize Google map, geolocate desktop user, and display after page loads
//find country, state, and city for the user's location - populate their respective input boxes - this all works
});
//change the Google Map after a user enters a street address
$("#streetAddress").blur(function() {
//if state, city and street address locations are present
if ( $(this).val().length > 0 && $("#state").val().length > 0 && $("#city3").val().length > 0 ) {
var gAddress = [$(this).val() + ", " + $("#city3").val() + ", " + $("#state").val()] ;
//if no geocode object exists, create one
if (!geocoder) {
geocoder = new google.maps.Geocoder(); //create Geocoder object else use existing one from initializeMap() ?
}
//create a GeocoderRequest object
var geoCoderRequest = {address: gAddress}
//make a Geocoder request
geocoder.geocode( geoCoderRequest, function(results, status) { //this line fails, apparently
//check if status is OK
if ( status === google.maps.GeocoderStatus.OK) {
//center existing map on location returned for this address
map.setCenter(results[0].geometry.location);
map.setZoom(14);
}
});
} else {
return; //no action if gAddress is incomplete
}
});