在 html5 中,哪个方法用于获得用户的当前位置

在 html5 中,哪个方法用于获得用户的当前位置,第1张

<!DOCTYPE html>

<html>

<body>

<p id="demo">点击这个按钮,获得您的坐标:</p>

<button onclick="getLocation()">试一下</button>

<script>

/*    例子解释:

    检测是否支持地理定位

    如果支持,则运行 getCurrentPosition() 方法。如果不支持,则向用户显示一段消息。

    如果getCurrentPosition()运行成功,则向参数showPosition中规定的函数返回一个coordinates对象

    showPosition() 函数获得并显示经度和纬度 */

    var x=document.getElementById("demo")

    function getLocation()

    {

        if (navigator.geolocation)

        {

            navigator.geolocation.getCurrentPosition(showPosition)

        }

        else{x.innerHTML="Geolocation is not supported by this browser."}

    }

    function showPosition(position)

    {

        x.innerHTML="Latitude: " + position.coords.latitude +

            "<br />Longitude: " + position.coords.longitude

    }

</script>

</body>

form 表单获取,<form action="要获取信息的地址或链接" method="get"> 用户名:<input type="text" name="username" />密 码:<input type="password" name="pwd" /></form>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/6126321.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-15
下一篇2023-03-15

发表评论

登录后才能评论

评论列表(0条)

    保存