Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made it possible to show more than two waypoints and made travelmethod

matter in the search
  • Loading branch information...
commit fc63645dbbb60a67e47cd92cbb7a79bccff02d2b 1 parent 0907ec2
@phyrex1an authored
View
29 src/org/pathpal/DirectionsForm.java
@@ -2,12 +2,26 @@
import java.io.IOException;
import java.util.*;
+import com.amelie.driving.DrivingDirections.Mode;
import android.location.Address;
public class DirectionsForm {
- public enum TravelMethod {BUS, WALK};
+ public enum TravelMethod {
+ UNKNOWN (Mode.DRIVING),
+ DRIVE (Mode.DRIVING),
+ WALK (Mode.WALKING);
+
+ private Mode gmode;
+ TravelMethod(Mode mode) {
+ gmode = mode;
+ }
+
+ public Mode realMode() {
+ return gmode;
+ }
+ };
// A waypoint is a point along the travel path as entered by the user
// for example "closest pet store", "Ullevi" or "200m a head"
// A waypoint is ambiguous and needs extra information to resolve to a
@@ -27,7 +41,6 @@ public Address findAddress(SearchApi api) throws IOException {
}
private class CurrentLocation implements Waypoint {
-
public Address findAddress(SearchApi api) throws IOException {
return api.startLocation;
}
@@ -37,8 +50,8 @@ public Address findAddress(SearchApi api) throws IOException {
Leg(Waypoint destination) {
this.destination = destination;
}
- protected Waypoint destination;
- protected TravelMethod method = TravelMethod.WALK;
+ private Waypoint destination;
+ private TravelMethod method = TravelMethod.UNKNOWN;
public Waypoint destination() {
return destination;
@@ -73,8 +86,8 @@ public void startAt(String address) {
startAt(new WaypointAddress(address));
}
- public void byBus() {
- travelPath.get(travelPath.size()-1).method = TravelMethod.BUS;
+ public void byCar() {
+ travelPath.get(travelPath.size()-1).method = TravelMethod.DRIVE;
}
public DirectionsForm travelTo(Waypoint destination) {
@@ -85,6 +98,10 @@ public DirectionsForm travelTo(Waypoint destination) {
public DirectionsForm travelTo(String address) {
return this.travelTo(new WaypointAddress(address));
}
+
+ public DirectionsForm andBackHere() {
+ return this.travelTo(new CurrentLocation());
+ }
public List<Leg> getTravelPath() {
return new ArrayList<Leg>(travelPath);
View
44 src/org/pathpal/GMapsActivity.java
@@ -212,7 +212,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
SearchApi api = new SearchApi(new Geocoder(getApplicationContext()), null); // TODO: null == current location
DirectionsForm directionForm = new DirectionsForm();
-
+ /*
try {
boolean work =TranslatorApi.translateString(nlp, directionForm, getResources().openRawResource(R.raw.locator));
@@ -231,33 +231,27 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
} catch (UnknownLanguageException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
- }
+ } */
+ directionForm.startAt("ullevi");
+ directionForm.travelTo("gamla ullevi");
+ directionForm.travelTo("brunnsparken");
+
- Address fromAddress = null;
- Address toAddress = null;
try {
- Waypoint curLoc = directionForm.startingLocation();
- List<Leg> path = directionForm.getTravelPath();
-
- fromAddress = curLoc.findAddress(api);
- toAddress = path.get(0).destination().findAddress(api);
-
- final int convert = 1000000;
- System.out.println("==================" + fromAddress.getLatitude() + "===============" + (int) (fromAddress.getLatitude()*convert));
-
-
- GeoPoint startPos = geopointfromDouble(fromAddress.getLatitude(), fromAddress.getLongitude());
- GeoPoint endPos = geopointfromDouble(toAddress.getLatitude(), toAddress.getLongitude());
- DrivingDirections dd = new DrivingDirectionsGoogleKML();
- dd.driveTo(startPos, endPos, Mode.DRIVING, this);
- mapController.animateTo(startPos);
-
- // output the user input to log
- System.out.println("====================");
- System.out.println(from + " " + to);
- System.out.println("====================");
-
+ Address fromAddress = null;
+ fromAddress = directionForm.startingLocation().findAddress(api);
+ for (Leg curLeg : directionForm.getTravelPath()) {
+ Waypoint toWaypoint = curLeg.destination();
+ Address toAddress = toWaypoint.findAddress(api);
+ DirectionsForm.TravelMethod method = curLeg.method();
+ GeoPoint startPos = geopointfromDouble(fromAddress.getLatitude(), fromAddress.getLongitude());
+ GeoPoint endPos = geopointfromDouble(toAddress.getLatitude(), toAddress.getLongitude());
+ DrivingDirections dd = new DrivingDirectionsGoogleKML();
+ dd.driveTo(startPos, endPos, curLeg.method().realMode(), this);
+ mapController.animateTo(startPos);
+ fromAddress = toAddress;
+ }
} catch (IOException e) {
e.printStackTrace();
} catch (IndexOutOfBoundsException e){
View
6 src/org/pathpal/test/DirectionsFormTest.java
@@ -35,12 +35,12 @@ public void testSimpleTravelPath() {
public void testDefaultTravelMethod() {
form.travelTo(destination);
- assertEquals(form.getTravelPath().get(0).method(), DirectionsForm.TravelMethod.WALK);
+ assertEquals(form.getTravelPath().get(0).method(), DirectionsForm.TravelMethod.UNKNOWN);
}
public void testTravelMethod() {
- form.travelTo(destination).byBus();
- assertEquals(form.getTravelPath().get(0).method(), DirectionsForm.TravelMethod.BUS);
+ form.travelTo(destination).byCar();
+ assertEquals(form.getTravelPath().get(0).method(), DirectionsForm.TravelMethod.DRIVE);
}
public void testThreeStepTravel() {
Please sign in to comment.
Something went wrong with that request. Please try again.