location - determine if waypoint has been reached, and if it's missed, move on to the next one with android google maps -
i wrote method determine distance destination along path , determine distance next waypoint along path. problem is, don't go within 10 meters of waypoint it's not getting caught having been reached. sure, increase threshold of distance make waypoint met, i'd rather come solution determine if i've passed waypoint , skip (by adding waypointsreached list) move on next one. checking see if distance location waypoint increasing instead of decreasing won't work because may stray off path before waypoint.
can me wrap head around idea of way can determine if i've passed waypoint , move on next one?
here's method i've written distance final destination , next waypoint.
// method calculate distance destinatoin loaded route private void calculateroutetodestination(location location) { new asynctask<location, void, arraylist<double>>(){ @override protected arraylist<double> doinbackground(location... params) { arraylist<double> distances = new arraylist<double>(); location location = params[0]; //predefinedroutepoints int closestlocationindex = 0; double smallestdistance = -1; int cnt = 0; for(latlng ltlg : predefinedroutepoints) { // create new location object latlng coords location clocation = new location(""); clocation.setlatitude(ltlg.latitude); clocation.setlongitude(ltlg.longitude); // distance current location of points in array , set index array double cdistance = location.distanceto(clocation); if(smallestdistance == -1 || cdistance < smallestdistance) { closestlocationindex = cnt; smallestdistance = cdistance; } cnt++; } // index array of cloest point, calculate distance last point in array index (distance destination) double distancetodestination = 0; for(int = closestlocationindex; < predefinedroutepoints.size(); i++) { //log.d("home","iteration:"+i); if(i != (predefinedroutepoints.size() -1)) { location l1 = new location(""); l1.setlatitude(predefinedroutepoints.get(i).latitude); l1.setlongitude(predefinedroutepoints.get(i).longitude); location l2 = new location(""); l2.setlatitude(predefinedroutepoints.get(i+1).latitude); l2.setlongitude(predefinedroutepoints.get(i+1).longitude); distancetodestination += l1.distanceto(l2); } } // add distance user cloest point final output of distance destinatoin distancetodestination += smallestdistance; distances.add(distancetodestination); // check if need measure distance next waypoint double distancetonextwaypoint = 0; if(predefinedwaypoints.size() > 0){ if(predefinedwaypoints.size() != waypointsreached.size()) { (int = closestlocationindex; < predefinedwaypoints.get(waypointsreached.size()).waypointindex; i++) { location l1 = new location(""); l1.setlatitude(predefinedroutepoints.get(i).latitude); l1.setlongitude(predefinedroutepoints.get(i).longitude); location l2 = new location(""); l2.setlatitude(predefinedroutepoints.get(i + 1).latitude); l2.setlongitude(predefinedroutepoints.get(i + 1).longitude); distancetonextwaypoint += l1.distanceto(l2); } distancetonextwaypoint += smallestdistance; if(distancetonextwaypoint < 10) { waypointsreached.add(predefinedwaypoints.get(waypointsreached.size())); } distances.add(distancetonextwaypoint); } } return distances; } @override protected void onpostexecute(arraylist<double> v) { distancetodestinationtext.settext("destination destination: "+utilities.getmiles(v.get(0))+"mi"); if(v.size() > 1) { distancetonextwaypoint.settext("next waypoint: "+utilities.getmiles(v.get(1))+"mi"); } else { distancetonextwaypoint.setvisibility(view.gone); distancetonextwaypoint.settext("next waypoint: 0.0mi"); } } }.execute(location); }
Comments
Post a Comment