我使用google.loader.clientlocation进行了一些测试,来自:
http://www.google.com/jsapi
但测试结果为空:
if (google.loader.ClientLocation)
这是谷歌找不到IP信息时的行为。
我搜索了stackoverflow,有很多关于它的问题,但没有很好的答案。
我搜索了网络,看到了这两个链接:
https://groups.google.com/forum/?fromgroups=#!topic/google-ajax-search-api/8q_oG-Y9fp8
http://code.google.com/p/google-ajax-apis/issues/detail?id=586
https://groups.google.com/forum/?fromgroups=#!topic/google-ajax-search-api/rzoIh4RrtOQ
这似乎意味着应该使用导航器HTML地理位置。
谷歌API文档不再提到它。
我想确认一下google.loader.clientlocation是否还在工作?
我的代码如下:
<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
</head>
<body>
<script type="text/javascript">
function geoTest() {
if (google.loader.ClientLocation) {
var latitude = google.loader.ClientLocation.latitude;
var longitude = google.loader.ClientLocation.longitude;
var city = google.loader.ClientLocation.address.city;
var country = google.loader.ClientLocation.address.country;
var country_code = google.loader.ClientLocation.address.country_code;
var region = google.loader.ClientLocation.address.region;
var text = 'Your Location<br /><br />Latitude: ' + latitude + '<br />Longitude: ' + longitude + '<br />City: ' + city + '<br />Country: ' + country + '<br />Country Code: ' + country_code + '<br />Region: ' + region;
} else {
var text = 'Google was not able to detect your location';
}
document.write(text);
}
geoTest();
</script>
</body>
</html>
最佳答案
似乎这个API有点“被弃用”,尽管它仍然适用于某些IP。
这就是我从这里得到的答案:
http://code.google.com/p/google-ajax-apis/issues/detail?id=586
装载机中的地理定位功能本身尚未失效。我们在几年前就停止了对它的文档记录,并推荐了基于HTML的解决方案,因为它们提高了准确性,但目前还没有从加载程序中删除功能本身。谢谢!
因此,当找不到IP的位置时,google.loader.clientlocation为空