Is google.loader.clientlocation still supported

◇◆丶佛笑我妖孽 提交于 2019-11-26 09:54:34

问题


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

  • http://www.google.com/jsapi

But I get null for the test:

if (google.loader.ClientLocation) 

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

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

I searched the net and saw these 2 links:

  • 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

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

Google API documentation does not mention it anymore.

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

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>

回答1:


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

This is the answer I got from here:

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

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



来源:https://stackoverflow.com/questions/14195837/is-google-loader-clientlocation-still-supported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!