是否仍支持google.loader.clientlocation [英] Is google.loader.clientlocation still supported

查看:74
本文介绍了是否仍支持google.loader.clientlocation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



但我得到null测试:

  if(google.loader.ClientLocation)

这是Google没有找到IP信息时的行为。



我搜索了StackOverflow,并且有很多

我搜索了网络,看到了这2个链接:



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



Google API文档的确不再提及它。

我想确认Google谷歌google.loader.clientlocation是否仍在工作?



我的代码如下:

 < html> 
< head>
< script type =text / javascriptsrc =http://www.google.com/jsapi>< / script>
< / head>
< body>
< script type =text / javascript>
函数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 ='您的位置< br />< br />纬度:'+ latitude +'< br />经度:'+ longitude +'< br /> ;城市:'+ city +'< br />国家:'+ country +'< br />国家代码:'+ country_code +'< br /> Region:'+ region;

} else {

var text ='Google无法检测到您的位置;

}

document.write(text);
}

geoTest();

< / script>
< / body>
< / html>


解决方案

看起来这个API有点不赞成它仍然适用于某些IP地址。



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


  • http://code.google.com/ p / google-ajax-apis / issues / detail?id = 586

  • $ b


    Loader中的地理定位功能本身并未退役。我们在几年前停止记录它,并且由于它们的准确性提高而推荐基于HTML的解决方案,但是此时尚未从Loader中删除功能本身。

    所以当找不到IP地址时,google.loader.ClientLocation为空


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

    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:

    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>
    

    解决方案

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

    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!

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

    这篇关于是否仍支持google.loader.clientlocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆