php - 使用谷歌地图跟踪车辆或手机位置

标签 php mysql codeigniter

  <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 数据库中的详细信息,并且我希望以标记点的方式进行跟踪到用户当前位置,然后随着用户移动而移动。

我已经尝试了上面的代码,但我对得到的结果不满意。

最佳答案

您将找到一个完整的工作示例,说明您正在尝试执行的操作 here

遗憾的是,由于 W3C/IETF 根本拒绝承认后台地理定位要求,您必须将应用程序保持在前台才能正常工作:-(

关于php - 使用谷歌地图跟踪车辆或手机位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52988562/

相关文章:

mysql - 比较 Grails 查询中日期的时间部分

php - 使用 lightopenid/注销保留登录信息

用于语言翻译的php函数

php - 如何根据键从表中选择一组随机行?

php - Twig 中的 str_replace

php - 在 PHP 中使用 optgroup 迭代下拉列表

php - Doxygen 使用 php __construct() 跳过文件

php - 如何构建 SQL 查询以从两个表和一个序列化列获取数据

php - jquery php mysql 和 json 返回循环数据

mysql - 交换两个不同表的两列的值