1st version that works
This commit is contained in:
126
libSafeMobile/src/main/java/com/safemobile/lib/HistPosmsg.java
Normal file
126
libSafeMobile/src/main/java/com/safemobile/lib/HistPosmsg.java
Normal file
@ -0,0 +1,126 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//Date data = Calendar.getInstance().getTime();
|
||||
//data.getTime();
|
||||
|
||||
public class HistPosmsg extends TCPmsg {
|
||||
|
||||
public ArrayList<HistPos> PosList;
|
||||
public int count=0;
|
||||
public HistPosmsg(TCPmsg tcp) {
|
||||
super(tcp);
|
||||
PosList = new ArrayList<HistPos>();
|
||||
try{
|
||||
String date4parsing = super.data;
|
||||
//SM.Debug("SMS date4parsing:"+date4parsing);
|
||||
String[] tempArr = date4parsing.split(";");
|
||||
//SM.Debug("SMS tempArr.length:" +tempArr.length);
|
||||
for(int i =0; i<tempArr.length;i++)
|
||||
{
|
||||
String[] tempVeh = tempArr[i].split("&");
|
||||
|
||||
if(tempVeh.length<6)
|
||||
continue;
|
||||
HistPos tmpLast = new HistPos();
|
||||
tmpLast.lat = Double.parseDouble(tempVeh[1]);
|
||||
tmpLast.lng = Double.parseDouble(tempVeh[2]);
|
||||
tmpLast.speed = Integer.parseInt(tempVeh[3]);
|
||||
tmpLast.timeGMT = Long.parseLong(tempVeh[5]);
|
||||
tmpLast.Address = tempVeh[6];
|
||||
//tmpLast.Address = "";
|
||||
|
||||
PosList.add(tmpLast);
|
||||
//SM.Debug("duda",tmpLast.toString());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
SM.Debug("Error on parse hisotry:"+e.toString());
|
||||
}
|
||||
CalcHeadingForArray(PosList);
|
||||
count +=this.PosList.size();
|
||||
SM.Debug("duda","HistList size:" +this.PosList.size() + " total:" +count);
|
||||
}
|
||||
|
||||
public ArrayList<HistPos> CalcHeadingForArray(ArrayList<HistPos> list)
|
||||
{
|
||||
this.PosList = list;
|
||||
if (PosList.size()>1)
|
||||
{
|
||||
HistPos oldPos = PosList.get(0);
|
||||
HistPos tmpPos = null;
|
||||
int Headingtmp =0;
|
||||
for (int i=1;i<PosList.size();i++)
|
||||
{
|
||||
tmpPos = PosList.get(i);
|
||||
Headingtmp = CalcHead(tmpPos.lng, tmpPos.lat, oldPos.lng, oldPos.lat, Headingtmp);
|
||||
tmpPos.heading = Headingtmp;
|
||||
oldPos = tmpPos;
|
||||
}
|
||||
}
|
||||
|
||||
return this.PosList;
|
||||
}
|
||||
|
||||
private int CalcHead(double lastLocX, double lastLocY, double prevLocX, double prevLocY, int heading)
|
||||
{
|
||||
double dlng = lastLocX - prevLocX;
|
||||
double dlat = lastLocY - prevLocY;
|
||||
double mdelta_min = -0.00001;
|
||||
double delta_min = 0.00001;
|
||||
int headcalc = 0;
|
||||
double blat = 0;
|
||||
double blng = 0;
|
||||
if ((dlat > mdelta_min) && (dlat < delta_min) && ((mdelta_min < dlng) && dlng < (delta_min))) headcalc = heading;
|
||||
else
|
||||
{
|
||||
if ((mdelta_min < dlat) && (dlat < delta_min))
|
||||
{
|
||||
blng = 1;
|
||||
if (dlng < 0) headcalc = 180;
|
||||
else headcalc = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
blat = 1;
|
||||
if (dlat > 0) headcalc = 90;
|
||||
else headcalc = 270;
|
||||
}
|
||||
}
|
||||
if ((mdelta_min < dlng) && (dlng < delta_min))
|
||||
{
|
||||
if (blat == 0)
|
||||
{
|
||||
if (dlat > 0)
|
||||
{
|
||||
if (headcalc == 180) headcalc = 135;
|
||||
if (headcalc == 0) headcalc = 45;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (headcalc == 180) headcalc = 225;
|
||||
if (headcalc == 0) headcalc = 315;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (blng == 0)
|
||||
{
|
||||
if (dlng < 0)
|
||||
{
|
||||
if (headcalc == 90) headcalc = 135;
|
||||
if (headcalc == 270) headcalc = 225;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (headcalc == 90) headcalc = 45;
|
||||
if (headcalc == 270) headcalc = 315;
|
||||
}
|
||||
}
|
||||
}
|
||||
return headcalc;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user