Response title
This is preview!
<script src="http://maps.google.com/maps?file=api&v=2&key=your_api_key" type="text/javascript"> </script>
<script type="text/javascript"> $('#searchcity').live('click',function(){ //You need to change these two variables as per your element id. //I hav used city1 and city2 as id in html code. var city1=$('#city1').val(); var city2=$('#city2').val(); if(city1=='City From...'){city1='';} if(city2=='City From...'){city2='';} var geocoder, location1, location2, miledistance, kmdistance; geocoder = new GClientGeocoder(); geocoder.getLocations(city1, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the first address"); } else { location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address }; geocoder.getLocations(city2, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the second address"); } else { location2 = {lat: response.Placemark[0].Point.coordinates[1], lon:response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; try { var glatlng1 = new GLatLng(location1.lat, location1.lon); var glatlng2 = new GLatLng(location2.lat, location2.lon); miledistance= glatlng1.distanceFrom(glatlng2, 3959).toFixed(1); kmdistance=(miledistance * 1.609344).toFixed(1); kmdistance=(kmdistance*1).toFixed(-1); //upper kmdistance is exact distance between two places. //no need to change upper code. //Now you just pass this kmdistance to server using post request. $.post('scripts/search_stamps_by_city.jsp', {distance:kmdistance},function(data){ $('.each_stamp').hover( function(){ $(this).css({'background-color' : ' #b4aeae '});}, function(){ $(this).css({'background-color' : '#ddd7d7', 'font-weight':'normal'});} );}); } catch (error){alert(error);}}});} }); }); </script>
<div id="citysearch_box"> <input id="city1" name="city1" value="City From..." type="text"> <input id="city2" name="city2" value="City To..." type="text"> <input id="searchcity" value="Search" type="submit"> </div>
© 2013 jQuery Foundation
Sponsored by and others.