Google maps 如何在不加载整个Google Maps API的情况下加载Google ClientLocation API?

Google maps 如何在不加载整个Google Maps API的情况下加载Google ClientLocation API?,google-maps,geolocation,geocoding,Google Maps,Geolocation,Geocoding,我所要做的就是找出这个人的IP地址,这样我就可以对其进行反向地理编码,以找出他们查看我的网站的纬度和经度 我可以用谷歌地图来实现这一点,但我不清楚是否需要加载巨大的谷歌地图框架才能使用它 是否可以简单地使用ClientLocation API而不必加载所有Google地图?如果是,怎么做?是的,您只需要在google.loader名称空间中使用ClientLocation对象,因此不需要引用maps api或其他任何内容。比如说 <script src="http://www.google

我所要做的就是找出这个人的IP地址,这样我就可以对其进行反向地理编码,以找出他们查看我的网站的纬度和经度

我可以用谷歌地图来实现这一点,但我不清楚是否需要加载巨大的谷歌地图框架才能使用它


是否可以简单地使用ClientLocation API而不必加载所有Google地图?如果是,怎么做?

是的,您只需要在google.loader名称空间中使用ClientLocation对象,因此不需要引用maps api或其他任何内容。比如说

<script src="http://www.google.com/jsapi" language="javascript"></script>
<script language="javascript">
if (google.loader.ClientLocation != null) {
  alert(google.loader.ClientLocation.address.city);
} else {
  alert("Not found");
}
</script>

if(google.loader.ClientLocation!=null){
警报(google.loader.ClientLocation.address.city);
}否则{
警报(“未找到”);
}
可用的属性包括

  • google.loader.ClientLocation.latitude
  • google.loader.ClientLocation.longitude
  • google.loader.ClientLocation.address.city
  • google.loader.ClientLocation.address.country
  • google.loader.ClientLocation.address.country_代码
  • google.loader.ClientLocation.address.region


国家名称: 编写(geoip_country_name());
城市: document.write(geoip_city());
纬度: document.write(geoip_lation());
经度: document.write(geoip_longitude()); 希望这对你有用
您可以选择在服务器端执行此操作,还是仅限于基于javascript客户端的解决方案?最好使用HTML5地理位置。请看。您好,每次我在else block登陆时,请您指导我。@Abhishek当Google无法定位IP地址时,clientLocation对象为空,这可能是由于多种原因,例如API无法解析您的IP地址。
<html>
    <head>
        <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
        <br>Country Name:
        <script language="JavaScript">document.write(geoip_country_name());</script>
        <br>City:
        <script language="JavaScript">document.write(geoip_city());</script>
        <br>Latitude:
        <script language="JavaScript">document.write(geoip_latitude());</script>
        <br>Longitude:
        <script language="JavaScript">document.write(geoip_longitude());</script>
    </head>
    <body>
        Hope this will be useful for you
    </body>
</html>