Google API客户端位置

时间:2012-02-22 18:22:09

标签: javascript api location

我想检测浏览器客户端位置,所以我写了这段代码:

 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。 谷歌是否禁用了ClientLocation功能?

0 个答案:

没有答案