Javascript 谷歌客户端定位API问题

Javascript 谷歌客户端定位API问题,javascript,api,Javascript,Api,我使用谷歌API来检测客户端位置,但它总是向我显示“谷歌加载器未检测到您的位置” 我需要找到客户所在地的国家代码,但它不适合我 <script src="http://www.google.com/jsapi" language="javascript"></script> <script language="javascript"> if (google.loader.ClientLocation != null) {

我使用谷歌API来检测客户端位置,但它总是向我显示“谷歌加载器未检测到您的位置”

我需要找到客户所在地的国家代码,但它不适合我

    <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>

if(google.loader.ClientLocation!=null){
document.write(“您的位置是:“+google.loader.ClientLocation.address.country_code”);
}否则{
write(“Google Loader未检测到您的位置”);
}

当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){
var latitude=google.loader.ClientLocation.latitude;
var longtudent=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\u代码;
}否则{
//找不到或未填充ClientLocation
//因此,请执行错误处理
}
改变

if(google.loader.ClientLocation!=null){

if(google.loader.ClientLocation){


希望,这会有帮助。

你在传递=什么吗?@Sheeraz,正如GBD提到的,你需要传递密钥。要进行地理定位,你需要传递并查看