使用Javascript无需互联网获取GPS位置 [英] Get GPS location using Javascript without Internet

查看:162
本文介绍了使用Javascript无需互联网获取GPS位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨如果设备有GPS硬件,我们可以使用没有互联网连接的JavaScript获取GPS位置吗?

Hi Can we get GPS location using javascript without internet connection if device has GPS hardware?

请注意谁将其标记为重复

我需要javascript才能在没有互联网连接的情况下工作,并使用GPS硬件来确定位置。

I need javascript to work without internet connection and use GPS hardware to determine the location.

推荐答案

Javascript可以通过 navigator.geolocation 向您显示地理位置。

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); 
}

这篇关于使用Javascript无需互联网获取GPS位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆