2016-11-16 23 views
0

我需要从浏览器获取用户经纬度,以显示与其位置相关的内容。如何设置功能以在浏览器中获取用户位置?

我发现一些网站要求允许访问您的位置问题,当我们加载它。

我可以知道我该如何做代码点火器或任何基于PHP的网站?

+0

谷歌是您的朋友:HTTP:// WWW .w3schools.com/html/html5_geolocation.asp – JazZ

+0

你的答案在这里:http://stackoverflow.com/questions/409999/getting-the-location-from-an-ip-address –

回答

1

HTML5具有地理定位功能,这可能是你想的访问请求:

Geolocation request

http://www.w3schools.com/HTML/html5_geolocation.asp

<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> 
相关问题