【问题标题】:Is google.loader.clientlocation still supportedgoogle.loader.clientlocation 是否仍受支持
【发布时间】:2012-12-21 04:12:57
【问题描述】:

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

但我的测试结果为 null:

if (google.loader.ClientLocation) 

这是 google 找不到 IP 信息时的行为。

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

我在网上搜索并看到了这两个链接:

这似乎是说应该使用导航器 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>

【问题讨论】:

  • 它仍在工作,但不可靠
  • 感谢您的回答,您是否有一些这样的链接。从我提到的第二个链接来看,似乎甚至谷歌都告诉使用其他东西。
  • 我没有链接,但我知道,因为昨天它为我返回了一个结果(不好,离我的位置 300 公里)。可能没有积极的支持,但它仍然存在(否则我昨天不会得到结果,google.loader.ClientLocation 在没有可用结果时将是undefined,但它是null)。我还没有看到任何官方声明不再支持它,新闻组内的评论不是官方声明。
  • 但第二个链接来自 google-ajax-apis 的 google 工程师。我的问题更多是关于它仍然被谷歌支持或接近被放弃。
  • 我找不到任何关于它是官方支持还是弃用的文档,但在当前源 https://www.google.com/jsapi 中,它显示为 google.loader.ClientLocation = null;。但是,虽然ClientLocation 被初始化为null,但它既没有被调用也没有分配给代码中的其他任何地方,因此对google.loader.ClientLocation 的调用可能会在调用时返回null。

标签: html geolocation google-api google-geocoding-api


【解决方案1】:

看起来这个 API 有点“不推荐使用”,尽管它仍然适用于某些 IP。

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

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

所以当没有为 IP 找到位置时,google.loader.ClientLocation 为空

【讨论】:

  • 那你是用什么来获取用户当前位置的?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-07
  • 2017-08-28
  • 1970-01-01
  • 2010-09-08
  • 1970-01-01
  • 2018-08-02
相关资源
最近更新 更多