简体   繁体   English

如何从谷歌地图方向API获取经度和纬度数组

[英]How to get array of latitude and longitude array from google maps direction api

I am creating Tracking software. 我正在创建跟踪软件。 Android device is sending its location and now I have to check if that location is within that direction set by the admin. Android设备正在发送其位置,现在我必须检查该位置是否在管理员设置的方向之内。

Basically, admin set a route for an employee (employee is using an android phone) using google maps (could be saved as series of latitude and longitude in database ), if location sent by an employee (latitude , longitude) is not in his route then admin will get a notification on website. 基本上,如果员工发送的位置(纬度,经度)不在他的路线中,则管理员使用Google地图(可以将其保存为一系列经纬度在数据库中)为员工(员工使用的是Android手机)设置路线然后管理员将在网站上收到通知。 I want help with camparison. 我需要Camparison的帮助。 Simply i want to know if employee is deviated from its route or not . 我只是想知道员工是否偏离了自己的路线。 Is it possible to do it? 有可能做到吗? Please do answer I will be very grateful. 请回答我将非常感谢。

<script>
  function initMap() {
    var directionsService = new google.maps.DirectionsService;
    var directionsDisplay = new google.maps.DirectionsRenderer;
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 7,
      center: {lat: 41.85, lng: -87.65}
    });
    directionsDisplay.setMap(map);

    var onChangeHandler = function() {
      calculateAndDisplayRoute(directionsService, directionsDisplay);
    };
    document.getElementById('start').addEventListener('change', onChangeHandler);
    document.getElementById('end').addEventListener('change', onChangeHandler);
  }

  function calculateAndDisplayRoute(directionsService, directionsDisplay) {
    directionsService.route({
      origin: document.getElementById('start').value,
      destination: document.getElementById('end').value,
      travelMode: 'DRIVING'
    }, function(response, status) {
      if (status === 'OK') {
          console.log(response);
        directionsDisplay.setDirections(response);
      } else {
        window.alert('Directions request failed due to ' + status);
      }
    });
  }
</script>

Can I extract array of latitude and longitude from variable response? 我可以从变量响应中提取纬度和经度数组吗? If there is better way please share. 如果有更好的方法,请分享。

Your question is quite broad and therefore my answer will be broad too but that would be too much to write in a comment... 您的问题很广泛,因此我的回答也会很广泛,但是在评论中写得太多了……

A route returned by the Directions service is not a collection of points or coordinates. 路线服务返回的路线不是点或坐标的集合。 It's a collection of legs and steps, with a start and end point (and an encrypted Polyline). 它是腿和步骤的集合,带有起点和终点(以及加密的折线)。 See here for details . 有关详细信息,请参见此处

As a side note, encoded Polylines can be decoded too, see here for more info. 附带说明,编码的折线也可以解码,有关更多信息,请参见此处

Coordinates you might get from the employee devices might not be 100% accurate and thus might not fall exactly on the directions path. 您从员工设备获得的坐标可能不是100%准确的,因此可能不会完全落在指示路径上。 So you will need some tolerance calculation. 因此,您将需要一些公差计算。

You might want to check the Roads API and more specifically the Snap to roads and/or Nearest services. 您可能要检查Roads API ,尤其是要检查与道路和/或最近的服务对齐

Alternatively, the Geometry library (which you need to load with your API call) also has a method called isLocationOnEdge which you can use to determine whether a point falls on or near a Polyline, based on a custom degree tolerance. 另外, Geometry库 (您需要通过API调用加载)还具有一个名为isLocationOnEdge的方法,您可以使用该方法基于自定义度公差来确定点在多义线上还是附近。

Hope this helps you get started! 希望这可以帮助您入门!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Google Maps V3 API获取经度和纬度? - How to get latitude and longitude from google maps v3 api? 如何获得与Google Maps URL的纬度和经度值相同的Google Geocoder API几何值(经度和纬度) - How to get the Google Geocoder API geometry values (latitude and longitude) same as Google maps URL latitude and longitude values 通过输入邮政编码从谷歌地图 API 获取经度和纬度 - get longitude & latitude from google maps API by entering zipcode 如何从数组中只获取经度和纬度 - How to get only longitude and latitude from array 如何在Google Maps Geolocation API中获取笔记本电脑(wifi)的纬度和经度? - How get latitude and longitude of laptop (wifi) in Google Maps Geolocation API? 从Google地图行程中获取经度 - Get latitude longitude from google maps itinerary 如何从Google地图中的地址获取经度值? - How to get latitude longitude value from an address in Google Maps? Google Maps API - 如何在不显示地图的情况下从自动完成获取纬度和经度? - Google Maps API - how to get latitude and longitude from Autocomplete without showing the map? 如何从函数获取纬度经度并将其发送到新的google.maps.LatLng(latitude,longitude)javascript - how to get latitude longitude from function and send it to new google.maps.LatLng( latitude ,longitude ) javascript 如何获取经度和纬度的谷歌在Javascript地图 - how to get longitude and latitude of google maps in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM