$(function(){ var map = new GMap2(document.getElementById('map_canvas')); var lat = 43.050827; var lon = -87.90367; var zoom = 10; var distance = 50; var locationStr = 'Zip code or City, State...'; var midwest = 0; var startLatLon = new GLatLng(lat,lon); //alert('zoom='+zoom+' distance='+distance); //alert("lat = " + lat + "lon = " + lon); map.setUIToDefault(); map.setCenter(startLatLon, zoom); var geo = new GClientGeocoder(); loadLocations(lat, lon, locationStr, distance, zoom); var reasons=[]; reasons[G_GEO_SUCCESS] = 'Success'; reasons[G_GEO_MISSING_ADDRESS] = 'Missing Address'; reasons[G_GEO_UNKNOWN_ADDRESS] = 'Unknown Address.'; reasons[G_GEO_UNAVAILABLE_ADDRESS]= 'Unavailable Address'; reasons[G_GEO_BAD_KEY] = 'Bad API Key'; reasons[G_GEO_TOO_MANY_QUERIES] = 'Too Many Queries'; reasons[G_GEO_SERVER_ERROR] = 'Server error'; $('#carxlocation').submit(function(){ geoEncode(); return false; }); $('#carxlocationhdr').submit(function(){ geoEncode(); return false; }); function resetPoint(geocode) { map.clearOverlays(); $('#location_area').empty(); var newLatLon = new GLatLng(geocode[1],geocode[0]); var newAddress = $('#carxlocation input[name=address]').val(); var newDistance = $('#distance').val(); var newZoom = $('#zoom').val() * 1; map.setCenter(newLatLon, newZoom); loadLocations(geocode[1], geocode[0], newAddress, newDistance, newZoom); } String.prototype.trim = function () { return this.replace(/^\s*/, "").replace(/\s*$/, ""); } function geoEncode() { var address = $('#carxlocation input[name=address]').val(); var no_Comma; var comma_Del; var chr_Check; if (isNaN(address)) { if (address.indexOf(",") == -1) { no_Comma = true; } else { comma_Del = address.indexOf(",") } if (no_Comma) { alert("Please specify a zip code or \"City, State\"") return false; } chr_Check = address.substring(comma_Del + 1); //chr_Check = chr_Check.trim(); if (chr_Check.length < 2) { alert("Please specify! a zip code or \"City, State\""); return false; } } geo.getLocations(address, function (result){ if (result.Status.code == G_GEO_SUCCESS) { geocode = result.Placemark[0].Point.coordinates; resetPoint(geocode); } else { var reason='Code '+result.Status.code; if (reasons[result.Status.code]) { reason = reasons[result.Status.code] } alert(reason); geocode = false; } }); } function addLocation(location) { var point = new GLatLng(location.lat, location.lng); // Create the car-x marker icon var carxIcon = new GIcon(G_DEFAULT_ICON); carxIcon.image = 'http://www.carx.com/images/map_pin.png'; carxIcon.shadow = 'http://www.carx.com/images/map_pin_shadow.png'; carxIcon.iconSize = new GSize(36, 21); carxIcon.shadowSize = new GSize(44, 29); carxIcon.iconAnchor = new GPoint(18, 11); carxIcon.infoWindowAnchor = new GPoint(18, 11); // Set up our GMarkerOptions object markerOptions = { icon:carxIcon }; var marker = new GMarker(point, markerOptions); map.addOverlay(marker); var locationText = '

' + location.address1 + '

' + '

' + location.city + '  ' + location.distance + '

'; var markerText = '

Car-X Tire & Auto

' + '

' + location.address1 + '
' + location.address2 + '

' + location.phone + '

' + location.hours + '

Click here for coupons for this location

'; GEvent.addListener(marker, 'click', function() { showMessage(marker, markerText); }); $('
') .html(locationText) .click(function(){ showMessage(marker, markerText); }) .appendTo("#location_area"); } function showMessage(marker, text){ map.panTo(marker.getLatLng()); marker.openInfoWindowHtml(text); } function loadLocations(strLatitude, strLongitude, strAddress, strDistance, strZoom) { var locationURL = 'googleLocations.asp?latitude=' + strLatitude + '&longitude=' + strLongitude + '&distance=' + strDistance + '&zoom=' + strZoom + '&address=' + strAddress; //document.write(locationURL); $.getJSON(locationURL, function(json) { if (json.Locations.length > 0) { for (i=0; iNo locations found for this search'); } }); } function adjustZoom(zoomValue) { switch(zoomValue) { case '10': $('#zoom').val("11"); break; case '25': $('#zoom').val("10"); break; case '50': $('#zoom').val("9"); break; case '100': $('#zoom').val("8"); break; default: $('#zoom').val("5"); } } $('.map_submit').bind('click', function(){ $('#carxlocation').submit(); }); $('#distance').change(function(e){ adjustZoom(e.target.value); }); $('#carxlocation input[name=address]').change(function(){ adjustZoom($('#distance').val()); $('#carxlocationhdr input[name=addresshdr]').val(this.value); }); $('#carxlocationhdr input[name=addresshdr]').change(function(){ adjustZoom($('#distance').val()); $('#carxlocation input[name=address]').val(this.value); }); $('.map_submithdr').bind('click', function(){ $('#carxlocation').submit(); }); });