javascript - 如何使用 IP 地理定位记录位置?
问题描述
我有一个使用 Geolocation DB 脚本的脚本,该脚本根据用户的 IP 跟踪用户的位置。我是新手,正在寻找一种方法来记录被跟踪的位置,以便我可以看到它们。
这是脚本/HTML。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<div>State: <span id="state"></span></div>
<div>City: <span id="city"></span></div>
<div>Latitude: <span id="latitude"></span></div>
<div>Longitude: <span id="longitude"></span></div>
<div>IP: <span id="ip"></span></div>
<script>
$.getJSON('https://geolocation-db.com/json/')
.done (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>
因此它将在用户的屏幕上显示用户的位置。我需要一种方法来查看它。我该怎么办?谢谢!
解决方案
看看这个。我已经纠正了这一点。
$(document).ready(function(){
$.getJSON('https://geolocation-db.com/json/')
.done (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 src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>State: <span id="country"></span></div>
<div>State: <span id="state"></span></div>
<div>City: <span id="city"></span></div>
<div>Latitude: <span id="latitude"></span></div>
<div>Longitude: <span id="longitude"></span></div>
<div>IP: <span id="ip"></span></div>
推荐阅读
- django - uWSGI - chdir():没有这样的文件或目录 [core/uwsgi.c line 2629]
- android - Android应用程序如何实时提醒设备?
- json - React.js:setState 方法将变量设置为字符串而不是对象......有解决方法吗?
- c# - 面向对象编程的帮助或建议?
- apache - 什么是在 Apache 中执行透明内容协商
- java - 我可以将 JLabels 添加到数组中吗?
- video-streaming - 视频流
- ruby-on-rails-5 - 如何在 ActiveAdmin 中使用日期选择器而不重写创建表单?
- c - 循环后挂在输入上的 PDCurses
- docker - Docker:OpenShift Origin 3.6 上的权限错误