From 709872b2c5db961fb12ce52a4122478e716dce00 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 9 Apr 2010 13:03:35 -0400 Subject: [PATCH] Updated some class names to match a recent Google change. --- www/maps/maps/controllers/directions.py | 40 +++++++++---------- .../maps/templates/javascript/routing.mako | 12 +++--- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/www/maps/maps/controllers/directions.py b/www/maps/maps/controllers/directions.py index d1c0d15..f7fa553 100644 --- a/www/maps/maps/controllers/directions.py +++ b/www/maps/maps/controllers/directions.py @@ -20,9 +20,9 @@ class DirectionsController(BaseController): # Google geocodes the start and end coordinates # automatically. There's no other way to pass the "name" of a - # route back to the server, so we have to rely on the geocoded + # leg back to the server, so we have to rely on the geocoded # names for identification. - def get_route_address(self, route, start=True): + def get_leg_address(self, leg, start=True): location_string = "start" if not start: @@ -31,7 +31,7 @@ class DirectionsController(BaseController): location_string = "end" # Get the GeocoderResponse object. - gr = route[location_string + '_geocode'] + gr = leg[location_string + '_geocode'] try: return gr['formatted_address'] @@ -41,24 +41,24 @@ class DirectionsController(BaseController): def directions_result_to_placemarks(self, result): placemarks = [] - trip_idx = 0 + route_idx = 0 - for trip in result['trips']: - trip_idx += 1 + for route in result['routes']: + route_idx += 1 - for route in trip['routes']: + for leg in route['legs']: p = KML.Placemark() - route_start = self.get_route_address(route, True) - route_end = self.get_route_address(route, False) - route_name = route_start + " to " + route_end - route_name += ' (' + str(trip_idx) + ')' - name_element = KML.Name(route_name) + leg_start = self.get_leg_address(leg, True) + leg_end = self.get_leg_address(leg, False) + leg_name = leg_start + " to " + leg_end + leg_name += ' (' + str(route_idx) + ')' + name_element = KML.Name(leg_name) p.children.append(name_element) ls = KML.LineString() coords = KML.Coordinates() - for step in route['steps']: + for step in leg['steps']: for coord in step['lat_lngs']: coords.text += str(coord.values()[0]) coords.text += ',' @@ -90,16 +90,16 @@ class DirectionsController(BaseController): def directions_result_to_csv(self, result): rows = [] - for trip in result['trips']: + for route in result['routes']: - for route in trip['routes']: - route_start = self.get_route_address(route, True) - route_end = self.get_route_address(route, False) - row = '"' + route_start + '"' + for leg in route['legs']: + leg_start = self.get_leg_address(route, True) + leg_end = self.get_leg_address(route, False) + row = '"' + leg_start + '"' row += ', ' - row += '"' + route_end + '"' + row += '"' + leg_end + '"' row += ', ' - row += str(float(route['distance']['value']) / 1000) + row += str(float(leg['distance']['value']) / 1000) rows.append(row) return rows diff --git a/www/maps/maps/templates/javascript/routing.mako b/www/maps/maps/templates/javascript/routing.mako index 1c72efd..3477d6b 100644 --- a/www/maps/maps/templates/javascript/routing.mako +++ b/www/maps/maps/templates/javascript/routing.mako @@ -33,12 +33,12 @@ function routing_callback(result, status) { if (status == google.maps.DirectionsStatus.OK) { json_string += JSON.stringify(result); - for (var trip_idx = 0; trip_idx < result.trips.length; trip_idx++) { - num_routes = result.trips[trip_idx].routes.length; - if (num_routes > 1) { - alert("Unexpected number of routes (" + - result.trips.routes.length.toString() + - ") on trip number " + trip_idx.toString() + '.'); + for (var route_idx = 0; route_idx < result.routes.length; route_idx++) { + var num_legs = result.routes[route_idx].legs.length; + if (num_legs > 1) { + alert("Unexpected number of legs (" + + result.routes.legs.length.toString() + + ") on route number " + route_idx.toString() + '.'); } } } -- 2.44.2