Hi All,
Im trying to get current location Lat,long and postcode from my desktop im getting default city Lat,long and postcode but i want the current located Lat,long and postcode
i tried this code...
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {
maximumAge: 0
});
$('body').append("");
} else {
$('body').append("");
}
function successCallback(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var geocoder = new google.maps.Geocoder();
var latLng = new google.maps.LatLng(latitude,longitude);
alert(latLng);
if (geocoder) {
geocoder.geocode({ 'latLng': latLng}, function (results,status) {
if (status.match(google.maps.GeocoderStatus.OK)) {
var address = results[0].address_components;
var zipcode = address[address.length - 1].long_name;
alert(zipcode);
//alert(results[0].formatted_address);
}
});
}
}
function errorCallback(error) {
var msg = "
Can't get your location. Error = ";
if (error.code == 1)
msg += "PERMISSION_DENIED";
else if (error.code == 2)
msg += "POSITION_UNAVAILABLE";
else if (error.code == 3)
msg += "TIMEOUT";
msg += ", msg = "+error.message;
$('body').append(msg);
}
Im getting the lat,long and postcode but not accurate one....