我找到了一个用谷歌解决地理定位的脚本 在这段代码中有一个86 char long的键
我已经为该网站的Gmail打开了一个google api密钥 它是一个短键(只有39个字符)
然后我改变了密钥并运行代码。我得到了我需要的解析国家/地区位置。 我然后尝试从另一个ip位置(在家里)和一个与代理服务器,并没有得到任何东西
我不确定我使用的api密钥是否设置为公共或不 - 我如何检查? 我是否需要为使用它付费,或者只能每天免费使用25,000个请求?
我试过的代码是:
<script type="text/javascript" src="http://www.google.com/jsapi?key="></script>
<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>