问题
Hi Can we get GPS location using javascript without internet connection if device has GPS hardware?
Please note who are marking it as duplicate
I need javascript to work without internet connection and use GPS hardware to determine the location.
回答1:
Javascript can show you geolocation via navigator.geolocation
.
function getLocation()
{
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(showPosition);
else
console.log("Geolocation is not supported by this browser");
}
function showPosition(position)
{
console.log("Latitude: " + position.coords.latitude);
console.log("Longitude: " + position.coords.longitude);
}
来源:https://stackoverflow.com/questions/17312826/get-gps-location-using-javascript-without-internet