Cosmetic tweaks to Python Route Guide
This commit is contained in:
parent
191628f359
commit
0acb6f70a6
|
|
@ -39,10 +39,9 @@ _TIMEOUT_SECONDS = 30
|
|||
|
||||
|
||||
def make_route_note(message, latitude, longitude):
|
||||
route_note = route_guide_pb2.RouteNote(message=message)
|
||||
route_note.location.latitude = latitude
|
||||
route_note.location.longitude = longitude
|
||||
return route_note
|
||||
return route_guide_pb2.RouteNote(
|
||||
message=message,
|
||||
location=route_guide_pb2.Point(latitude=latitude, longitude=longitude))
|
||||
|
||||
|
||||
def guide_get_one_feature(stub, point):
|
||||
|
|
@ -63,11 +62,11 @@ def guide_get_feature(stub):
|
|||
|
||||
|
||||
def guide_list_features(stub):
|
||||
rect = route_guide_pb2.Rectangle()
|
||||
rect.lo.latitude = 400000000
|
||||
rect.lo.longitude = -750000000
|
||||
rect.hi.latitude = 420000000
|
||||
rect.hi.longitude = -730000000
|
||||
rect = route_guide_pb2.Rectangle(
|
||||
lo=route_guide_pb2.Point(
|
||||
latitude=400000000, longitude = -750000000),
|
||||
hi=route_guide_pb2.Point(
|
||||
latitude = 420000000, longitude = -730000000))
|
||||
print "Looking for features between 40, -75 and 42, -73"
|
||||
|
||||
features = stub.ListFeatures(rect, _TIMEOUT_SECONDS)
|
||||
|
|
|
|||
|
|
@ -73,20 +73,16 @@ class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer):
|
|||
|
||||
def GetFeature(self, request, context):
|
||||
feature = get_feature(self.db, request)
|
||||
if not feature:
|
||||
feature = route_guide_pb2.Feature(
|
||||
name="",
|
||||
location=route_guide_pb2.Point(
|
||||
latitude=request.latitude, longitude=request.longitude))
|
||||
return feature
|
||||
if feature is None:
|
||||
return route_guide_pb2.Feature(name="", location=request)
|
||||
else:
|
||||
return feature
|
||||
|
||||
def ListFeatures(self, request, context):
|
||||
lo = request.lo
|
||||
hi = request.hi
|
||||
left = min(lo.longitude, hi.longitude)
|
||||
right = max(lo.longitude, hi.longitude)
|
||||
top = max(lo.latitude, hi.latitude)
|
||||
bottom = min(lo.latitude, hi.latitude)
|
||||
left = min(request.lo.longitude, request.hi.longitude)
|
||||
right = max(request.lo.longitude, request.hi.longitude)
|
||||
top = max(request.lo.latitude, request.hi.latitude)
|
||||
bottom = min(request.lo.latitude, request.hi.latitude)
|
||||
for feature in self.db:
|
||||
if (feature.location.longitude >= left and
|
||||
feature.location.longitude <= right and
|
||||
|
|
|
|||
Loading…
Reference in New Issue