First of all you have used all scripts twice, one from local and one from external URL, so cleanup.
Secondly, on save button you cannot access results object as it is defined in GetLocation
Thirdly, the place where you make AJAX call is also incorrect, here's a working sample.
HTML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/json2/0.1/json2.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnSave]").bind("click", function () {
GetLocation($("#txtAddress").val());
return false;
});
});
function GetLocation(address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var location = {};
location.lattitude = results[0].geometry.location.lat();
location.longitude = results[0].geometry.location.lng();
var mapOptions = {
center: new google.maps.LatLng(location.lattitude, location.longitude),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var latlngbounds = new google.maps.LatLngBounds();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
//Call AJAX function here
alert(JSON.stringify(location));
$.ajax({
type: "POST",
url: "Default.aspx/SaveLocation",
data: JSON.stringify(location),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert(r.d);
}
});
} else {
alert("Location not found.");
}
});
};
</script>
<input type="text" id="txtAddress" value="Churchgate, Mumbai, India" />
<input type="button" id="btnSave" value="Save" />
<hr />
<div id="dvMap" style="height: 300px; width: 300px">
</div>
Code
[System.Web.Services.WebMethod]
public static string SaveLocation(string lattitude, string longitude)
{
return "Latitude: " + lattitude + " Longitude: " + longitude;
}