[英]Google ClientLocation API issue
我正在使用Google API來檢測客戶端位置,但是它始終向我顯示“ Google加載程序未檢測到您的位置”。
我需要找到客戶所在位置的國家/地區代碼,但是對我來說不起作用。
<script src="http://www.google.com/jsapi" language="javascript"></script>
<script language="javascript">
if (google.loader.ClientLocation != null) {
document.write("Your Location Is: " + google.loader.ClientLocation.address.country_code);
} else {
document.write("Your Location Was Not Detected By Google Loader");
}
</script>
當Google無法定位您的IP地址時,ClientLocation對象返回null。 發生這種情況的原因有很多,其中之一就是API無法解析您的IP地址。
也許您可以嘗試其他解決方案,例如
或要求您的服務器執行此操作。
嘗試這個:
<script type="text/javascript">
if(google.loader.ClientLocation) {
var latitude = google.loader.ClientLocation.latitude;
var longtitude = google.loader.ClientLocation.longitude;
var city = google.loader.ClientLocation.address.city;
var region = google.loader.ClientLocation.address.region;
var country = google.loader.ClientLocation.address.country;
var countrycode = google.loader.ClientLocation.address.country_code;
} else {
// ClientLocation not found or not populated
// so perform error handling
}
</script>
更改
if (google.loader.ClientLocation != null) {
至
if (google.loader.ClientLocation){
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.