注入页面以自动读取用户的 IP 并吐出他们的城市的最新、准确、交钥匙代码是什么......在这个页面上,我们从 gotorain.com 借来我希望它显示.. . 3英里范围内(动态城市)
4 回答
我们一直在寻找使用的另一个是http://www.maxmind.com/app/geolitecity。看起来设置起来相当简单,并且是开源/免费的,带有适用于大多数流行语言的 api。
除了玩了 5 分钟之外没有做太多,但看起来很有希望。
我会选择位置感知浏览。查看W3C GeoLocation API。
例如,试试Google Gears 地理定位模块。
这些技术使您的客户不仅可以通过查看和他们的 IP(可以有 200 公里的偏移量)进行地理定位,还可以通过对来自附近无线接入点的 SSID 信息进行三角测量,这可以非常精确。
一旦你有了 (lon,lat) 坐标,只需调用一些网络服务来获取最近的城市名称。
I would choose the locator API at http://ipinfodb.com You can access it via XML or JSON, send it your API key and an IP and it will return the city, state, zip, country, etc. You can then parse the results in your language of choice. Its the simplest way to achieve this without actually storing any information about IP/location routing.
是的,您只需要使用 google.loader 命名空间中的 ClientLocation 对象。总的来说,整个代码是。
<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