Google API 客户端位置
我想检测浏览器客户端位置,所以我编写了这段代码:
if(google.loader.ClientLocation)
{
var visitor_lat = google.loader.ClientLocation.latitude;
var visitor_lon = google.loader.ClientLocation.longitude;
var visitor_city = google.loader.ClientLocation.address.city;
var visitor_region = google.loader.ClientLocation.address.region;
var visitor_country = google.loader.ClientLocation.address.country;
var visitor_countrycode = google.loader.ClientLocation.address.country_code;
document.getElementById('yourinfo').innerHTML = '<p>Lat/Lon: ' + visitor_lat + ' / ' + visitor_lon + '</p><p>Location: ' + visitor_city + ', ' + visitor_region + ', ' + visitor_country + ' (' + visitor_countrycode + ')</p>';
alert("Found Location");
}
else
{
// ClientLocation not found or not populated
// so perform error handling
alert("Could not find client location... ");
}
我看过许多其他网络教程,这段代码应该可以工作,但它不适合我:S。 与 Google 禁用 ClientLocation 功能有关吗?
I want to detect the browser client location, so I wrote this code:
if(google.loader.ClientLocation)
{
var visitor_lat = google.loader.ClientLocation.latitude;
var visitor_lon = google.loader.ClientLocation.longitude;
var visitor_city = google.loader.ClientLocation.address.city;
var visitor_region = google.loader.ClientLocation.address.region;
var visitor_country = google.loader.ClientLocation.address.country;
var visitor_countrycode = google.loader.ClientLocation.address.country_code;
document.getElementById('yourinfo').innerHTML = '<p>Lat/Lon: ' + visitor_lat + ' / ' + visitor_lon + '</p><p>Location: ' + visitor_city + ', ' + visitor_region + ', ' + visitor_country + ' (' + visitor_countrycode + ')</p>';
alert("Found Location");
}
else
{
// ClientLocation not found or not populated
// so perform error handling
alert("Could not find client location... ");
}
I have looked at many other web tutorials, and this code should work, but it doesn't for me :S.
Is it something about Google disabling ClientLocation function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论