使用jQuery / JS(没有谷歌地理定位API)查找用户位置? [英] Find user location using jQuery/JS (without google geolocation api)?

查看:104
本文介绍了使用jQuery / JS(没有谷歌地理定位API)查找用户位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法只使用jQuery在网站上找到客户位置。例如,如果用户访问我的网站,我怎么能找到他们的大概位置只是使用jQuery。例如,如果用户来自旧金山CA,则会有一些类型标识符让我知道用户来自旧金山CA.我真的不需要他们的确切位置只是县或一般的原产地。

Is there a way to find a clients location on a website using just jQuery. For example, if a user comes to my site, how could I find out what their approximate location is just using jQuery. For example, if a user came from San Francisco CA it would have some type identifier to let me know the user came from San Francisco CA. I wouldn't really need their exact location just the county or general area of origin.

编辑:
如何关于 http://flourishworks-webutils.appspot.com/req 生成了什么?

谢谢

推荐答案

获取客户端IP地址& jQuery中的国家/地区名称:

To get the client IP address & country name in jQuery:

$.getJSON("http://freegeoip.net/json/", function(data) {
    var country_code = data.country_code;
    var country = data.country_name;
    var ip = data.ip;
    var time_zone = data.time_zone;
    var latitude = data.latitude;
    var longitude = data.longitude;

    alert("Country Code: " + country_code);
    alert("Country Name: " + country);
    alert("IP: " + ip); 
    alert("Time Zone: " + time_zone);
    alert("Latitude: " + latitude);
    alert("Longitude: " + longitude);   
});

$.get("http://freegeoip.net/json/", function (response) {
    $("#ip").html("IP: " + response.ip);
    $("#address").html("Location: " + response.city + ", " + response.region_name);
    $("#details").html(JSON.stringify(response, null, 4));
}, "jsonp");

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h3>Client side IP geolocation using <a href="http://freegeoip.net">freegeoip.net</a></h3>

<hr/>
<div id="ip"></div>
<div id="address"></div>
<hr/>Full response: <pre id="details"></pre>

这篇关于使用jQuery / JS(没有谷歌地理定位API)查找用户位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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