Get GPS location using Javascript without Internet [duplicate]

[亡魂溺海] 提交于 2019-12-06 05:38:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!