Skip to content

Commit

Permalink
Use search string as cloudmade track name, if possible. Added mapUtil…
Browse files Browse the repository at this point in the history
…s.Track.recalculateDistance()
  • Loading branch information
kipe committed Oct 9, 2012
1 parent bc88e3f commit 48afd18
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
8 changes: 6 additions & 2 deletions gmapcatcher/cmRoute.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

# http://routes.cloudmade.com/YOUR-API-KEY-GOES-HERE/api/0.3/start_point,[transit_point1,...,transit_pointN],end_point/route_type[/route_type_modifier].output_format[?lang=(Two letter ISO 3166-1 code)][&units=(km|miles)]
class cmRoute:
def __init__(self, apikey, start, end, transit_points=None, route_type='car'):
def __init__(self, apikey, start, end, transit_points=None, route_type='car', name=None):
self.apikey = apikey
self.start = start
self.end = end
self.transit_points = transit_points
self.route_type = route_type
self.name = name
# print self.apikey

def buildUrl(self):
Expand Down Expand Up @@ -55,7 +56,10 @@ def getWaypoints(self):
for waypoint in gpx.waypoints:
waypoints.append(TrackPoint(waypoint.latitude, waypoint.longitude))
if len(waypoints) >= 1:
return Track(waypoints, 'CloudMade waypoints', distance)
if self.name:
return Track(waypoints, self.name, distance)
else:
return Track(waypoints, 'CloudMade waypoints', distance)
return None


Expand Down
12 changes: 8 additions & 4 deletions gmapcatcher/mapUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,14 @@ def __init__(self, points, name=None, distance=None):
if distance:
self.distance = distance
else:
distance = 0
for i in range(0, len(points) - 1):
distance += countDistanceFromLatLon(points[i].getLatLon(), points[i + 1].getLatLon())
self.distance = distance
self.recalculateDistance()

def recalculateDistance(self):
distance = 0
for i in range(0, len(self.points) - 1):
distance += countDistanceFromLatLon(self.points[i].getLatLon(), self.points[i + 1].getLatLon())
self.distance = distance
return self.distance

class TrackPoint:
def __init__(self, latitude=None, longitude=None, timestamp=None, altitude=None, speed=None):
Expand Down
9 changes: 6 additions & 3 deletions maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,13 @@ def confirm_clicked(self, button):
locations = self.ctx_map.get_locations()
if len(found_locations) > 1:
points = []
searchStr = ''
for l in found_locations:
coord = locations[unicode(l)]
points.append(mapUtils.TrackPoint(coord[0], coord[1]))
self.getCloudMadeRoute(None, points)
searchStr += '%s - ' % l
searchStr = searchStr.rstrip(' - ')
self.getCloudMadeRoute(None, points, searchStr)
else:
self.entry.set_text(unicode(found_locations[0]))
coord = locations[unicode(found_locations[0])]
Expand Down Expand Up @@ -736,7 +739,7 @@ def ruler_popup(self):
menu.show_all()
return menu

def getCloudMadeRoute(self, w, points):
def getCloudMadeRoute(self, w, points, name=None):
if self.cb_offline.get_active():
if error_msg(self, "Offline mode, cannot get route!" +
" Would you like to get online?",
Expand All @@ -748,7 +751,7 @@ def getCloudMadeRoute(self, w, points):
transit_points = []
if len(points) > 2:
transit_points = points[1:-1]
cm = cmRoute(self.conf.cloudMade_API, start, end, transit_points)
cm = cmRoute(self.conf.cloudMade_API, start, end, transit_points, name=name)
track = cm.getWaypoints()
if track:
self.tracks.append(track)
Expand Down

0 comments on commit 48afd18

Please sign in to comment.