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和CSS3实现3D展示商品信息的代码
利用HTML5中的Canvas绘制笑脸的代码
Html5剪切板功能的实现
如何通过HTML5触摸事件实现移动端简易进度条
Html5移动端获奖无缝滚动动画实现
关于HTML5和CSS3实现机器猫的代码