35 #include "examples/protos/route_guide.grpc.pb.h"
37 #include "route_guide.grpc.pb.h"
47 using routeguide::RouteGuide;
50 using std::chrono::system_clock;
56 const float kCoordFactor = 10000000.0;
57 float lat_1 =
start.latitude() / kCoordFactor;
58 float lat_2 =
end.latitude() / kCoordFactor;
59 float lon_1 =
start.longitude() / kCoordFactor;
60 float lon_2 =
end.longitude() / kCoordFactor;
66 float a = pow(sin(delta_lat_rad / 2), 2) +
67 cos(lat_rad_1) * cos(lat_rad_2) * pow(sin(delta_lon_rad / 2), 2);
68 float c = 2 * atan2(sqrt(
a), sqrt(1 -
a));
75 const std::vector<Feature>& feature_list) {
76 for (
const Feature&
f : feature_list) {
77 if (
f.location().latitude() ==
point.latitude() &&
78 f.location().longitude() ==
point.longitude()) {
95 feature->mutable_location()->CopyFrom(*
point);
96 auto* reactor =
context->DefaultReactor();
107 const std::vector<Feature>* feature_list)
109 rectangle->hi().longitude())),
110 right_((
std::max)(rectangle->lo().longitude(),
111 rectangle->hi().longitude())),
112 top_((
std::max)(rectangle->lo().latitude(),
113 rectangle->hi().latitude())),
114 bottom_((
std::min)(rectangle->lo().latitude(),
115 rectangle->hi().latitude())),
120 void OnDone()
override {
delete this; }
121 void OnWriteDone(
bool )
override { NextWrite(); }
128 if (
f.location().longitude() >=
left_ &&
129 f.location().longitude() <= right_ &&
130 f.location().latitude() >= bottom_ &&
131 f.location().latitude() <= top_) {
144 std::vector<Feature>::const_iterator next_feature_;
159 void OnDone() {
delete this; }
160 void OnReadDone(
bool ok) {
166 if (point_count_ != 1) {
172 summary_->set_point_count(point_count_);
173 summary_->set_feature_count(feature_count_);
174 summary_->set_distance(
static_cast<long>(distance_));
175 auto secs = std::chrono::duration_cast<std::chrono::seconds>(
177 summary_->set_elapsed_time(secs.count());
187 int point_count_ = 0;
188 int feature_count_ = 0;
189 float distance_ = 0.0;
199 Chatter(
absl::Mutex*
mu, std::vector<RouteNote>* received_notes)
203 void OnDone()
override {
delete this; }
204 void OnReadDone(
bool ok)
override {
215 std::back_inserter(to_send_notes_),
217 return note.location().latitude() ==
218 note_.location().latitude() &&
219 note.location().longitude() ==
220 note_.location().longitude();
223 notes_iterator_ = to_send_notes_.begin();
229 void OnWriteDone(
bool )
override { NextWrite(); }
233 if (notes_iterator_ != to_send_notes_.end()) {
234 StartWrite(&*notes_iterator_);
246 std::vector<RouteNote> to_send_notes_;
266 std::cout <<
"Server listening on " <<
server_address << std::endl;
270 int main(
int argc,
char** argv) {