如何加载Google ClientLocation API而不加载整个Google Maps API? [英] How to load Google ClientLocation API without loading the whole Google Maps API?

查看:95
本文介绍了如何加载Google ClientLocation API而不加载整个Google Maps API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我可以使用 Google ClientLocation API 执行此操作,但尚不清楚对我来说,如果我必须加载庞大的Google Map框架才能使用它。



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

解决方案

是的,您只需要在google.loader命名空间中使用ClientLocation对象,参考地图API或其他任何东西。例如。

 < script src =http://www.google.com/jsapilanguage =javascript >< /脚本> 
< 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


All I want to do is find out the person IP address so that I can reverse geocode it to find out their latitude and longitude from which they are viewing my web site from.

I can do that using Google ClientLocation API but it's unclear to me if I have to load the huge Google Map framework just to use it.

Is it possible to simply use the ClientLocation API without having to load all of Google Maps? If so, how?

解决方案

Yes, you only need to use the ClientLocation object in the google.loader namespace so you need not reference the maps api or anything else. For example.

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

The properties available are

  • 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 ClientLocation API而不加载整个Google Maps API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆