我一直在尝试使用我的计算机ip
找到一种工具来定位我的位置。
我尝试了一些网络工具,例如http://geoiplookup.net/
和https://geoiptool.com/
以及一些开发人员工具,例如freegeoip.net
,我对此感兴趣。
事实是:地理位置在所有这些地方远离,至少我位于(南美洲,巴西),所有指向相同的错误位置< / em>的
为什么会这样?
我尝试过这段代码:
send_url = 'http://freegeoip.net/json'
r = requests.get(send_url)
j = json.loads(r.text)
lat = j['latitude']
lon = j['longitude']
return (lat, lon)
但是由于它使用了错误的ip
,它会返回一些奇怪的lat/lgn
,离我很远。
1)我可以在上面的代码中传递我的确切ip
作为参数吗?
2)除了lat, lng
之外,还有其他工具可以找出我的精确googlemaps
吗?
答案 0 :(得分:1)
与其他地理定位方法(如GPS或WiFi MAC地址)相比,IP地址地理定位的准确性相对较低。原因是ISP经常重新分配IP地址。
回到你的问题。
1)API应自动检测您的IP地址并返回估计的位置
2)如果没有启用GPS,您将无法找到精确的纬度和经度
答案 1 :(得分:0)
一个小的jQuery示例,用于检索位置,国家/地区,城市,纬度,经度,IP和状态:
<!DOCTYPE html>
<html>
<head>
<title>GEOIP DB - jQuery example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script>
</head>
<body>
<div>Country: <span id="country"></span>
<div>State: <span id="state"></span>
<div>City: <span id="city"></span>
<div>Latitude: <span id="latitude"></span>
<div>Longitude: <span id="longitude"></span>
<div>IP: <span id="IPv4"></span>
<script>
$.ajax({
url: "https://geoip-db.com/jsonp",
jsonpCallback: "callback",
dataType: "jsonp",
success: function( location ) {
$('#country').html(location.country_name);
$('#state').html(location.state);
$('#city').html(location.city);
$('#latitude').html(location.latitude);
$('#longitude').html(location.longitude);
$('#ip').html(location.IPv4);
}
});
</script>
</body>
</html>