17 html5 google-api geolocation google-geocoding-api
我使用google.loader.ClientLocation进行了一些测试:
但我在测试中得到null:
if (google.loader.ClientLocation)
Run Code Online (Sandbox Code Playgroud)
这是谷歌找不到IP信息时的行为.
我搜索了StackOverflow并且有很多关于它的问题,但没有好的答案.
我在网上搜索了这两个链接:
这似乎说应该使用导航器HTML地理位置.
Google API文档不再提及它了.
我想确认谷歌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>
Run Code Online (Sandbox Code Playgroud)
小智 16
看起来这个API有点"弃用",尽管它仍适用于某些IP.
这是我从这里得到的答案:
Loader中的地理定位功能本身尚未停用.几年前我们停止记录它,并且由于其准确性提高而推荐了基于HTML的解决方案,但此时功能本身尚未从Loader中删除.谢谢!
因此,当找不到IP的位置时,google.loader.ClientLocation为null