首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >google.loader.clientlocation是否仍受支持

google.loader.clientlocation是否仍受支持
EN

Stack Overflow用户
提问于 2013-01-07 20:21:13
回答 1查看 28.9K关注 0票数 18

我使用google.loader.ClientLocation做了一些测试,这些测试来自:

但是我在测试中得到了null:

代码语言:javascript
复制
if (google.loader.ClientLocation) 

这就是谷歌找不到知识产权信息时的行为。

我搜索了StackOverflow,有很多关于它的问题,但没有好的答案。

我在网上搜索了一下,发现了这两个链接:

这似乎表明应该使用导航器HTML地理位置。

Google API文档不再提及它。

我想确认一下 google.loader.clientlocation是否还在工作?

我的代码如下:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-10 01:59:45

这个API看起来有点“过时”了,尽管它仍然适用于一些IP。

这是我从这里得到的答案:

加载器中的地理定位功能本身并没有停用。我们在几年前就停止了对它的记录,并推荐了基于HTML的解决方案,因为它们提高了准确性,但功能本身目前还没有从Loader中删除。谢谢!

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

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14195837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档