谷歌.loader.clientlocation是否仍被支持?

18

我使用 google.loader.ClientLocation 进行了一些测试,来源于:

但是我的这个测试返回了 null:

if (google.loader.ClientLocation) 

当Google无法找到IP信息时的行为。

我在StackOverflow上搜索了很多相关问题,但没有好的答案。

我搜索了网络并看到了以下2个链接:

它们似乎都在说应该使用导航器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>

它仍然能工作,但不可靠。 - Dr.Molle
谢谢您的回答,您有一些链接可以证明吗?从我在问题中提到的第二个链接中看来,甚至Google也建议使用其他东西。 - user1565007
1
我没有链接,但是我知道它,因为昨天它给我返回了一个结果(不好的结果,距离我的位置300公里)。也许没有活跃的支持,但它仍然存在(否则我昨天就不会得到结果,当没有结果可用时google.loader.ClientLocation将是undefined,但它是null)。我没有看到任何官方声明说它不再受支持,新闻组内的评论不是官方声明。 - Dr.Molle
但第二个链接来自谷歌工程师在google-ajax-apis上。我的问题更多是关于它是否仍然得到谷歌的支持或即将被放弃。 - user1565007
第二个链接没有包含任何关于未来计划的细节。你可以向他们询问。 - Dr.Molle
1
我找不到任何关于它是否得到官方支持或已被弃用的文档,但在当前源代码 https://www.google.com/jsapi 中,它读取 google.loader.ClientLocation = null;。但是,虽然 ClientLocation 被初始化为 null,但它既没有被调用也没有被分配给代码中的其他任何地方,因此每当调用 google.loader.ClientLocation 时,它都将返回 null。 - zeantsoi
1个回答

16

尽管该API仍对某些IP地址有效,但它似乎已经有点“过时”了。

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

Loader中的地理位置功能并没有被彻底淘汰。我们几年前停止了对其进行文档记录,并推荐使用基于HTML的解决方案,因为它们具有更高的准确性,但该功能目前尚未从Loader中删除。谢谢!

因此,当IP地址未找到位置时,google.loader.ClientLocation将为空。


1
那么你用了什么来获取用户当前位置? - Abhishek saini

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接