Welcome to WebmasterWorld Guest from 107.21.159.218

Forum Moderators: open

Message Too Old, No Replies

My Validation for Google Maps V3 seems slighly off - any sugestions?

     

tec4

7:45 am on Nov 30, 2011 (gmt 0)



Hello Everyone,

I have a little search/mapping tool with Google Maps V3 and works fine and dandy to find locations when the geocoded address is within the radius of any of the locations in my MySQL database. However, when the geocode is successful and the address that was geocoded does not fall inside of the specific radius of the locations, my map centers to the center of the map (right smack dab in the middle of the ocean).

I've been trying to figure out exactly where to place a conditional statement to perhaps alert something like "Sorry no locations in your defined X miles" but I cant seem to figure out exactly where to place it/how to structure it to make it work...I keep breaking the map.

Was trying to place it somewhere in here:

function searchLocationsNear(center) {
clearLocations();

var radius = document.getElementById('radiusSelect').value;
var searchUrl = 'generate_xml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;

downloadUrl(searchUrl, function(data) {

var xml = parseXml(data);
var markerNodes = xml.documentElement.getElementsByTagName("marker");
var bounds = new google.maps.LatLngBounds();

for (var i = 0; i < markerNodes.length; i++) {
//sorry for this being so small...had to wrap in code tag because it was
//throwing an error when trying to post...it just loads variables for markers
 var name = markerNodes[i].getAttribute("name");
var address = markerNodes[i].getAttribute("address");
var distance = parseFloat(markerNodes[i].getAttribute("distance"));
var latlng = new google.maps.LatLng(
parseFloat(markerNodes[i].getAttribute("lat")),
parseFloat(markerNodes[i].getAttribute("lng")));


createOption(name, distance, i);
createMarker(latlng, name, address);
bounds.extend(latlng);
}

map.fitBounds(bounds);
locationSelect.style.visibility = "visible";
locationSelect.onchange = function() {
var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
google.maps.event.trigger(markers[markerNum], 'click');
};
});
}

Was trying to check if any markers exists and if not send an alert but no luck....any way to throw a conditional statement in there to alert the user instead of the map centering to the middle of the Pacific Ocean? lol
 

Featured Threads

Hot Threads This Week

Hot Threads This Month