微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html5 – 仍然支持google.loader.clientlocation

我已经使用google.loader.ClientLocation做了一些测试:

> http://www.google.com/jsapi

但是我测试中为null:

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地理位置。

Google Api文档不再提及。

我想要确认Google 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

The geolocation functionality in the Loader hasn’t been retired,per se. We stopped documenting it several years ago and have recommended the HTML-based solutions due to their improved accuracy,but the functionality itself has not been removed from the Loader at this time. Thanks!

所以当找不到IP的位置时,google.loader.ClientLocation为null

原文地址:/html5/168933.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。