I'm trying to get lng and lat coordinates of the Google Maps API by the next example http://jsbin.com/inepo3/7/edit. I expect a 'success' popup, but it keeps showing the 'Error' popup.
The google maps-request gives the correct json feedback (checked by firebug).
<script type=text/javascript>
$().ready(function() {
$.fn.getCoordinates=function(address){
$.ajax(
{
type : GET,
url: http://maps.google.com/maps/api/geocode/json,
dataType: jsonp,
data: {
address: address,
sensor: true
},
success: function(data) {
set = data;
alert(set);
},
error : function() {
alert(Error.);
}
});
};
$().getCoordinates(Amsterdam, Netherlands);
});
</script>
Does anyone know how to fix this issue?
Regards,
Guido Lemmens
EDIT
I found a bether solution using the Google Maps Javascript API combined in jQuery:
<script type=text/javascript>
$().ready(function() {
var user1Location = Amsterdam, Netherlands;
var geocoder = new google.maps.Geocoder();
//convert location into longitude and latitude
geocoder.geocode({
address: user1Location
}, function(locResult) {
console.log(locResult);
var lat1 = locResult[0].geometry.location.lat();
var lng1 = locResult[0].geometry.location.lng();
$(#testDiv).html(latitude: + lat1 + <p>longitude: + lng1 + </p>);
});
});
</script>