参考教程:http://www.w3school.com.cn/html5/html_5_geolocation.asp

 说明:设备必须有GPS定位功能才能定位的

 

定位用户的位置

HTML5 Geolocation API 用于获得用户的地理位置。

 

 

<!DOCTYPE html>
<html>
<body>
<p >点击这个按钮,获得您的坐标:</p>
<button onclick="getLocation()">试一下</button>
<script>
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>
</html>



说明:html5的定位还比较准,我在Android与iphone上都有测试过,另外这种定位方式也比较简单

 

相关文章:

  • 2021-07-14
  • 2021-12-10
  • 2022-02-03
  • 2021-12-05
  • 2021-11-23
  • 2022-12-23
  • 2021-09-26
猜你喜欢
  • 2022-12-23
  • 2021-12-17
  • 2021-12-21
  • 2021-11-23
  • 2021-11-23
  • 2022-01-17
相关资源
相似解决方案