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

标签 google-maps geolocation geocoding

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

我可以使用 Google ClientLocation API但我不清楚我是否必须加载巨大的谷歌地图框架才能使用它。

是否可以简单地使用 ClientLocation API 而无需加载所有 Google map ?如果是这样,怎么做?

最佳答案

是的,您只需要使用 google.loader 命名空间中的 ClientLocation 对象,因此您无需引用 map 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>

可用的属性是
  • google.loader.ClientLocation.latitude
  • google.loader.ClientLocation.longitude
  • google.loader.ClientLocation.address.city
  • google.loader.ClientLocation.address.country
  • google.loader.ClientLocation.address.country_code
  • google.loader.ClientLocation.address.region
  • 关于google-maps - 如何在不加载整个 Google Maps API 的情况下加载 Google ClientLocation API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3233767/

    相关文章:

    javascript - 函数声明不应放在 block 中

    google-maps - 谷歌地图未捕获类型错误 : Cannot read property 'offsetWidth' of null

    mysql - Geo IP数据库查询问题

    javascript - Bootstrap Modal 上的 Google map 为灰色 - 调整窗口大小使其显示

    jquery - 谷歌地图通过外部链接点击标记

    javascript - 如何根据互联网连接可用性切换基础层

    android - 如何使用内置的谷歌地图应用程序根据数据显示许多地点标记

    geolocation - 通过 IP 进行精确地理定位

    javascript - 使用谷歌地图 javascript API 搜索地址