public Route getRoute(WorldCoordinate c1, WorldCoordinate c2) {
if (lastC1 != null && lastC1.latitude == c1.latitude && lastC1.longitude == c1.longitude
&& lastC2.latitude == c2.latitude && lastC2.longitude == c2.longitude) {
return lastRoute;
}
lastC1 = new WorldCoordinate(c1);
lastC2 = new WorldCoordinate(c2);
try {
String routeGpx = IOTool.download("http://routes.cloudmade.com/e4b1777b4b5154d69dbfc4678216183a/api/0.3/"
+ c1.latitude + "," + c1.longitude + "," + c2.latitude + "," + c2.longitude + "/"
+ ROUTING_OPTIONS.get(Options.getInstance().routeType) + "?units=km&lang=en");
if (Options.getInstance().debugMode) {
System.out.println(routeGpx);
}
XmlParser parser = new XmlParser(new InputStreamReader(new ByteArrayInputStream(routeGpx.getBytes())));
Document doc = new Document();
doc.parse(parser);
parser = null;
Element root = doc.getRootElement();
Route result = new Route();
result.waypoints = new Vector();
result.routeDirections = new Vector();
for (int i = 0; i < root.getChildCount(); i++) {
Object child = root.getChild(i);
if (child instanceof Element) {
Element elem = (Element) child;
String name = elem.getName();
if (name.equals("extensions")) {
for (int j = 0; j < elem.getChildCount(); j++) {
Object child2 = elem.getChild(i);
if (child2 instanceof Element) {
Element elem2 = (Element) child2;
if (elem2.getName().equals("distance")) {
result.distance = Long.parseLong(elem2.getText());
}
}
}
} else if (name.equals("wpt")) {
WorldCoordinate c = new WorldCoordinate();
c.latitude = Double.parseDouble(elem.getAttribute("lat").getValue());
c.longitude = Double.parseDouble(elem.getAttribute("lon").getValue());
result.waypoints.addElement(c);
} else if (name.equals("rte")) {
for (int j = 0; j < elem.getChildCount(); j++) {