php - 使用谷歌地图跟踪车辆或手机位置
问题描述
<script>
var map, infoWindow;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 6
});
infoWindow = new google.maps.InfoWindow;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
infoWindow.open(map);
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
infoWindow.open(map);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=MY_API&callback=initMap">
</script>
我正在设计一个带有 php、CodeIgniter 和 MySQL 的系统,该系统将用于在旅途中使用 MySQL 数据库中的详细信息跟踪车辆或手机的当前位置,并且我希望它以标记指向当前的方式用户的位置,然后在用户移动的同时移动。
我已经尝试了上面的代码,但我对我得到的并不满意。
解决方案
您将在此处找到一个完整的工作示例,说明您正在尝试执行的操作
可悲的是,由于 W3C/IETF 只是拒绝承认后台地理定位要求,您必须将您的应用程序放在前台才能工作:-(
推荐阅读
- java - Java IDE 和构建工具是否依赖 `javac` 和 `java` 命令?
- javascript - 如何使用新浏览器中可用的扩展 JS 语法
- javascript - sorttable.js 在服务器上工作,但在内联时不行
- java - Maven,继承 pom 模块
- ios - CoreData 一对一关系:重新启动应用程序后对象为零
- sendgrid - Sendgrid 是否按收件人向您收费?
- javascript - 禁用表单提交 JQuery 上的按钮后,使用按钮名称将表单提交给 PHP
- vb.net - 如何调整大小和图像并保存为字节数组
- javascript - 如何在不覆盖先前值的情况下将多个值设置为同一个键?
- vba - 在 VBA 中使用 2 个向量的元素创建消息