有没有办法从客户端确定访客国家? [英] Is there a way to determine a visitors country from the client?

查看:125
本文介绍了有没有办法从客户端确定访客国家?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌地图和地理编码API在用户输入邮政编码后检索用户lat / lng,但我想限制邮政编码到该用户国家,所以我不会以多个结果。

有没有一种方法可以从客户端可靠地确定访客来源国家可能使用jquery或可能解码用户代理?



我的电话会看起来像这样:

  var country = ??? 
var postcode = document.getElementById('postcode')。value +','+ country;

var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address':postcode},function(results,status){
if(status == google.maps.GeocoderStatus.OK){
...
}
});

有什么想法?

解决方案

为了不依赖第三方,您可以通过使用谷歌的加载器这是一个很好的例子 ,加载Google Maps API和ClientLocation。


I'm using google maps and the geocoding API to retrieve a users lat/lng after they enter a zip/postal code but I want to limit the zip/postal codes to that users country so I don't end up with multiple results.

Is there a way to reliably determine a visitors country of origin from the client maybe using jquery or possible decoding the user agent somehow?

My call would end of looking something like this:

var country = ???
var postcode = document.getElementById('postcode').value + ', ' + country;

var geocoder = new google.maps.Geocoder();         
geocoder.geocode({ 'address': postcode }, function (results, status) {          
   if (status == google.maps.GeocoderStatus.OK) {  
       ...
   }
});

Any thoughts?

解决方案

For the benefit of not relying on a third-party, you can get the client's location by using Google's Loader. Here's a great example of this in use, loading the Google Maps API and ClientLocation.

这篇关于有没有办法从客户端确定访客国家?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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