I am using this code to get the accurate user's location...
watchID=navigator.geolocation.watchPosition(handleGetCurrentPosition, handleGetCurrentPositionError, {enableHighAccuracy:true});
function handleGetCurrentPosition(location)
{
document.getElementById("lat").value = location.coords.latitude;
document.getElementById("lon").value = location.coords.longitude;
document.getElementById("accu").value =location.coords.accuracy;
document.forms["myform"].submit();
}
function handleGetCurrentPositionError(){
alert("Location could not be found.")
}
bt the result i am getting is not accurate. Is there any problem the code i am using?
The accuracy depends on capabilities of your Geolocation
device. navigator.geolocation
is just an API
which works with that device. If the device does not support high accuracies, you can't do anything with it.
this the below code to get accurate location. i have written this code in HTML 5.
< output id="mapToYou" >Searching for your current location...< /output >
window.addEventListener("load", function() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(success, error); } else { error('not supported'); } },false); function success(position) { var mapToYou = document.querySelector('#mapToYou'); alert("Gotcha!"); var latlng = new google.maps.LatLng(position.coords.latitude,position.coords.longitude); var myOptions = { zoom: 15, center: latlng, mapTypeControl: false, navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL }, mapTypeId: google.maps.MapTypeId.ROADMAP }; var googleMap = new google.maps.Map(mapToYou, myOptions); var marker = new google.maps.Marker({ position: latlng, map: googleMap, title:"You are here!" }); } function error(msg) { var mapToYou = document.querySelector('#mapToYou'); mapToYou.innerHTML = typeof msg == 'string' ? msg : "failed"; mapToYou.className = 'fail'; // console.log(arguments); }
Have you tried Google's location api's?
If not, here is the link: https://developers.google.com/maps/documentation/directions/
Actually there are a lot of on-going APIs that are developed by Google to increase the accuracy of location finding
I found this useful link at : http://www.geoplugin.com , provides a very good location filtering API and has really scary precision at predicting user location.
Here is an example of how this is to be used: http://www.jquery4u.com/api-calls/geo-location-2-lines-javascript/#.T_QZrxdo3IU
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.