但是我测试中为null:
if (google.loader.ClientLocation)
这是谷歌没有找到IP信息的行为。
我搜索了StackOverflow,有很多问题,但没有很好的答案。
我在网上搜了一下,看到这两个链接:
> 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
应该使用哪个导航器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>
解决方法
这是我从这里得到的答案:
> 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!
所以当找不到IP的位置时,google.loader.ClientLocation为null