根据我的跟踪信息跟踪距离和时间 [英] track distance and time based on my track details

查看:136
本文介绍了根据我的跟踪信息跟踪距离和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的GPS跟踪机器人来跟踪用户的位置,并提供记录track.I我能画出路径现在我要计算的轨道距离和时间,像假设用户开始跟踪记录功能和移动到另一个位置,现在我要计算总距离,时间旅行从开始到结束位置(与用户位置更新)中的谷歌地图。我有函数计算出的距离为2的位置,但是这不适合我的路线,因为路线是折线和它的灵活纬度/经度位置。是他们的任何API或任何功能或服务,提供由谷歌。任何帮助或建议的AP preciate。

I am working on gps tracking in android to track the user location and provide the feature to record the track.I am able to draw path now i want to calculate the track distance and time with that like suppose user start tracking record and move to another location now i want to calculate total distance and time travel for from start to end position (with user location update) in google map. I have function which calculate the distance for 2 position but that not fit for my route, because route are in polyline and it's flexible lat/lng position. is their any api or any function or services provide by google for that. any help or suggestion are appreciate.

推荐答案

我想创建一个类的航点

class WayPoint
{
   DateTime depart; //some date time container
   DateTime arrive; //some date time container
   Coordinate position; //some gps coordinate
}

然后创建这些类,允许元素插入的是有帮助的任何位置的列表,如果您的路由改变:

Then create a list of these classes which allows inserting of elements at any position which is helpful if your route changes:

List<WayPoint> journey = new ArrayList<WayPoint>();

//just add your waypoints

journey.add(startWayPoint);
journey.add(wayPoint_1);
journey.add(wayPoint_2);
//...
journey.add(wayPoint_n_minus_2);
journey.add(wayPoint_n_minus_1);
journey.add(endWayPoint);

然后转换成数组并计算总计:

Then convert to array and calculate the totals:

WayPoint[] wayPoints = journey.toArray();

double total_distance = 0.0f; //distance in metres
double total_travel_time = 0.0f; // time in hours

//start at index 1 because there are n-1 segments
if(wayPoints.length>1)
foreach(int i=1; i<wayPoints.length;i++)
{
  total_distance += calcDistanceBetween(
      wayPoints[i-1].position,
      wayPoints[i].position);

  total_time += calcTimeInHoursBetween(
      wayPoints[i-1].depart,
      wayPoints[i].arrive);
}

log.d("Total Distance",String.valueOf(total_distance));
log.d("Total Travel Time",String.valueOf(total_travel_time));

这篇关于根据我的跟踪信息跟踪距离和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆