/
DirectionsForm.java
43 lines (32 loc) · 974 Bytes
/
DirectionsForm.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package org.pathpal;
import java.io.IOException;
import java.util.*;
import android.location.Address;
public class DirectionsForm {
// private List<Waypoint> waypoints = new ArrayList<Waypoint>();
private Waypoint to, from;
public interface Waypoint {
public abstract Address findLocation(SearchApi api) throws IOException;
}
private class AddressLine implements Waypoint {
private String name;
AddressLine(String name) {
this.name = name;
}
public Address findLocation(SearchApi api) throws IOException {
return api.geocoder.getFromLocationName(name, 0).remove(0);
}
}
public void goToAddress(String name) {
to = new AddressLine(name);
}
public void startAtAddress(String name) {
from = new AddressLine(name);
}
public List<Address> getWalkPath(SearchApi api) throws IOException {
List<Address> path = new ArrayList<Address>();
path.add(from.findLocation(api));
path.add(to.findLocation(api));
return path;
}
}