谷歌分析能够使用JavaScript库查找访问者位置。这怎么可以用javascript完成?如何使用javascript查找网站访问者位置?
2
A
回答
2
navigator.geolocation对象是您向用户代理询问其位置的方式。根据UA的设置,这可能会或可能不会提示用户允许/拒绝发送数据。此外,地理定位数据本身的精确度可能会非常变化(尽管如此,它们会给您一个裕量或误差,因此您可以将其考虑在内)。
if (navigator.geolocation) {
navigator.geolocation.getPosition(
successFunction,
failureFunction
);
} else {
noGeolocationFunction();
};
还有一个watchPosition方法。两者都是异步的,所以你传递成功/失败函数来处理返回的对象。
1
谷歌有一个查询访问者位置的API。 Find web visitor's location automatically with javascript and Google APIs
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Get web visitor's location</title>
<meta name="robots" value="none" />
</head>
<body>
<div id="yourinfo"></div>
<script type="text/javascript" src="http://www.google.com/jsapi?key=[apikey]"></script>
<script type="text/javascript">
if(google.loader.ClientLocation)
{
visitor_lat = google.loader.ClientLocation.latitude;
visitor_lon = google.loader.ClientLocation.longitude;
visitor_city = google.loader.ClientLocation.address.city;
visitor_region = google.loader.ClientLocation.address.region;
visitor_country = google.loader.ClientLocation.address.country;
visitor_countrycode = google.loader.ClientLocation.address.country_code;
document.getElementById('yourinfo').innerHTML = '<p>Lat/Lon: ' + visitor_lat + '/' + visitor_lon + '</p><p>Location: ' + visitor_city + ', ' + visitor_region + ', ' + visitor_country + ' (' + visitor_countrycode + ')</p>';
}
else
{
document.getElementById('yourinfo').innerHTML = '<p>Whoops!</p>';
}
</script>
</body>
</html>
相关问题
- 1. 如何在网站访问期间查找用户的位置?
- 2. 如何检测网站访问者的确切地理位置
- 3. 网站如何计算其他网站的访问者和“价值”,他们如何告知用户的位置?
- 4. 获取网站访问者的电子邮件提醒位置
- 5. 当访问者从网站
- 6. PHP从网站访问者
- 7. 隐藏*网站访问者
- 8. 寻找网站访问者的地理位置的解决方案
- 9. 如何将访问者限制为访问我网站的访问者
- 10. 我们如何找到Php的网站访问者总数?
- 11. 在Java中查找您的网站访问者IP地址
- 12. 网站优化 - 如何保存访问者网站选项?
- 13. 如何准确确定访问者在我的网站上的位置?
- 14. 如何跟踪访问者来自我的网站的位置php
- 15. 按python位置访问网站
- 16. 如何使用Cookie让访问者访问我的网站的下载页面
- 17. 查找上次访问的网站
- 18. 如何使用ESP8266访问网站?
- 19. 我可以为我的网站访问者启用JavaScript吗?
- 20. 如何限制按地理位置访问网站?
- 21. 使用cURL查找网站重定向的位置?
- 22. 如何从GPS提供者而不是网络提供者访问位置?
- 23. 如何从网页访问iPhone位置?
- 24. 如何查找网站中使用的Javascript库版本?
- 25. 使用PhoneGap访问网站
- 26. 使用HTML/JavaScript查找地理位置
- 27. 获取访问者的位置,使用GPS(如果可用)?
- 28. 如何检查我的网站是否使用爬虫访问?
- 29. 有人使用Google Analytics吗? Google如何避免将访问者的网站作为访问者?
http://stackoverflow.com/questions/3489460/how-to-get-visitors-location-ie-country-using-javascript-geolocation –
[也在该酮](HTTP:// WWW .opal-creations.co.uk /博客/免费的脚本和代码/ GET-A-游客-位置与JavaScript的)。 –