Html 是否仍支持 google.loader.clientlocation

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14195837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:47:01  来源:igfitidea点击:

Is google.loader.clientlocation still supported

htmlgeolocationgoogle-apigoogle-geocoding-api

提问by

I have made some tests using google.loader.ClientLocation from:

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

But I get null for the test:

但是我的测试结果为空:

if (google.loader.ClientLocation) 

This is the behaviour when google does not find information for IP.

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

I searched StackOverflow and there are a lot of questions regarding it but no good answers.

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

I searched the net and saw these 2 links:

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

Which seem to say the navigator HTML geo location should be used.

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

Google API documentation does not mention it anymore.

Google API 文档不再提及它。

I would like a confirmation of wether Google google.loader.clientlocation is still working or not ?

我想确认谷歌 google.loader.clientlocation 是否仍然有效?

My code is the following:

我的代码如下:

<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>

采纳答案by

It seems this API is kind of "deprecated" although it still works for some IPs.

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

This is the answer I got from here:

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

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!

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

So when location is not found for IP, google.loader.ClientLocation is null

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