【发布时间】:2012-12-21 04:12:57
【问题描述】:
我使用 google.loader.ClientLocation 做了一些测试,来自:
但我的测试结果为 null:
if (google.loader.ClientLocation)
这是 google 找不到 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>
【问题讨论】:
-
它仍在工作,但不可靠
-
感谢您的回答,您是否有一些这样的链接。从我提到的第二个链接来看,似乎甚至谷歌都告诉使用其他东西。
-
我没有链接,但我知道,因为昨天它为我返回了一个结果(不好,离我的位置 300 公里)。可能没有积极的支持,但它仍然存在(否则我昨天不会得到结果,
google.loader.ClientLocation在没有可用结果时将是undefined,但它是null)。我还没有看到任何官方声明不再支持它,新闻组内的评论不是官方声明。 -
但第二个链接来自 google-ajax-apis 的 google 工程师。我的问题更多是关于它仍然被谷歌支持或接近被放弃。
-
我找不到任何关于它是官方支持还是弃用的文档,但在当前源
https://www.google.com/jsapi中,它显示为google.loader.ClientLocation = null;。但是,虽然ClientLocation被初始化为null,但它既没有被调用也没有分配给代码中的其他任何地方,因此对google.loader.ClientLocation的调用可能会在调用时返回null。
标签: html geolocation google-api google-geocoding-api