简体   繁体   English

如何计算两个gio点(lat和lng)之间的距离?

[英]How to calculate the distance between two gio points( lat and lng )?

I am working on an ITS(Intelligent Transport System). 我正在研究ITS(智能运输系统)。 So I have to calculate the EAT(Estimated Arrival Time) at the bus stop for a bus. 因此,我必须计算公交车站的EAT(预计到达时间)。 Now I have the two points(lat, lng) of stop and position of vehicle at present. 现在,我现在有车辆的停止位置和位置两个点(纬度,经度)。 So I have to calculate distance. 所以我必须计算距离。 next I ll get speed SO I can calculate the Arrival Time at the stop for bus. 接下来,我将提高速度,这样我就可以计算公交车站的到站时间。 My problem is, I am using this method to calculate distance between two points, 我的问题是,我正在使用这种方法来计算两点之间的距离,

private double distance(double lat1, double lon1, double lat2, double lon2, char unit) {

      double theta = lon1 - lon2;
      double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
      dist = Math.acos(dist);
      dist = rad2deg(dist);
      dist = dist * 60 * 1.1515;
      if (unit == 'K') {
        dist = dist * 1.609344;
      } else if (unit == 'N') {
        dist = dist * 0.8684;
        }
      return (dist);

    }

What I am thinking is, it calculates the straight line distance between two points. 我在想的是,它计算两点之间的直线距离。 It wont happen in real time. 它不会实时发生。 because a vehicle travel by road. 因为车辆是公路行驶。 So is there any better solution or algorithm to find out the distance between two places. 因此,有没有更好的解决方案或算法来找出两个地方之间的距离。 Please any one help me in this. 请任何人在这方面帮助我。

The distance depends on the bus route. 距离取决于公交路线。

If your Intelligent Transport System knows the bus route, then you can use that info. 如果您的智能运输系统知道公交路线,则可以使用该信息。

Does Google Maps have these bus routes? Google地图有这些公交路线吗? You can use the Google Maps API to ask it for transit routes from the origin point to the destination point, but you'll have to determine which of the choices are right, if any. 您可以使用Google Maps API向其询问从起点到目的地的公交路线,但是您必须确定哪个选择正确(如果有)。

If your actual goal is to determine the ETA, then what you need is the transit schedule, not the distance. 如果您的实际目标是确定ETA,那么您需要的是运输时间表,而不是距离。 (The passenger needs to wait for the bus to arrive, the bus may wait at certain stops to meet up with other lines, and so on.) The Google Maps API can help with this as long as it knows about the relevant bus lines. (乘客需要等待公共汽车的到来,公共汽车可能会在某些车站等待与其他线路的接驳,依此类推。)只要知道相关的公共汽车线路,Google Maps API就可以提供帮助。

You are right, calculating the direct distance of two geographical position will not be enough as routes are often not straight. 没错,计算两个地理位置的直接距离是不够的,因为路线通常不是直线。 Google map api can help you in this case. 在这种情况下,Google Map API可以为您提供帮助。

You can use the google map Direction Service . 您可以使用谷歌地图方向服务 Checkout the following Transit mode: 签出以下运输方式:

https://developers.google.com/maps/documentation/javascript/directions#TravelModes https://developers.google.com/maps/documentation/javascript/directions#TravelModes

Offcourse, you have to take in consideration the stop time and average speed of the bus. 偏离路线时,您必须考虑公共汽车的停车时间和平均速度。 Since bus will not always have the same speed, you need to calculate the average speed, keep traffic lights and other related things into consideration (may be traffic jam even?). 由于公交车的行驶速度不一定总是相同的,因此您需要计算平均速度,并考虑交通信号灯和其他相关事项(甚至可能会堵车)。 It will be best, if your estimated time also shows possible delays and update it in real time (when bus will be in traffic jam, in can add the waiting time with delay time). 最好是,如果您的估计时间还显示可能的延迟并实时更新(当公共汽车将出现交通拥堵时,可以在等待时间中加上延迟时间)。

You can use the LatLangTool method below 您可以在下面使用LatLangTool方法

  public static Double getDistanceToLocation(SourceCordinate from, SourceCordinate to) {
        LatLng busDeparturePoint = new LatLng(from.latitude, from.longitude);
        LatLng busDestinationPoint = new LatLng(to.latitude, to.longitude);


        return LatLngTool.distance(busDeparturePoint, busDestinationPoint, LengthUnit.KILOMETER);
    }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM