i = 0 #新增 def ListFeatures(self, request, context): global i #新增 i = i + 1 #新增 print(i) #新增 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) y=0 #新增 for feature in self.db: y = y+1 #新增 print(y) #新增 if (feature.location.longitude >= left and feature.location.longitude <= right and feature.location.latitude >= bottom and feature.location.latitude <= top): yield feature
客户端
def guide_list_features(stub): rectangle = 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(rectangle) i=0 #新增 for feature in features: i = i+1 #新增 if i > 10: #新增 break #新增 print("get No.:%d" % i) print("Feature called %s at %s" % (feature.name, feature.location))
原文:https://www.cnblogs.com/codetouse/p/14363335.html