blob: 93cb2bf963fc793aa2d88c5990b2d231077b9660 [file] [log] [blame]
Jorge Canizales34b26292015-06-02 02:11:09 -07001/*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#import <UIKit/UIKit.h>
35#import <RouteGuide/RouteGuide.pbrpc.h>
36
37static NSString * const kHostAddress = @"http://localhost:50051";
38
Jorge Canizalesc9885952015-06-05 17:41:00 -070039// Category to override RTGPoint's description.
40@interface RTGPoint (Description)
41- (NSString *)description;
42@end
43
44@implementation RTGPoint (Description)
45- (NSString *)description {
46 NSString *verticalDirection = self.latitude >= 0 ? @"N" : @"S";
47 NSString *horizontalDirection = self.longitude >= 0 ? @"E" : @"W";
48 return [NSString stringWithFormat:@"%.02f%@ %.02f%@",
49 abs(self.latitude) / 1E7f, verticalDirection,
50 abs(self.longitude) / 1E7f, horizontalDirection];
51}
52@end
Jorge Canizales3fda5482015-06-05 12:05:00 -070053
Jorge Canizales34b26292015-06-02 02:11:09 -070054#pragma mark Get Feature
55
Jorge Canizales3aed7172015-06-04 22:56:21 -070056// Run the getFeature demo. Calls getFeature with a point known to have a feature and a point known
57// not to have a feature.
58
Jorge Canizales34b26292015-06-02 02:11:09 -070059@interface GetFeatureViewController : UIViewController
60@end
61
62@implementation GetFeatureViewController
63
64- (void)viewDidLoad {
65 [super viewDidLoad];
66
67 RTGRouteGuide *client = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
68
Jorge Canizales3aed7172015-06-04 22:56:21 -070069 void (^handler)(RTGFeature *response, NSError *error) = ^(RTGFeature *response, NSError *error) {
70 if (response.name.length) {
71 NSLog(@"Found feature called %@ at %@.", response.name, response.location);
72 } else if (response) {
73 NSLog(@"Found no features at %@", response.location);
74 } else {
75 NSLog(@"RPC error: %@", error);
76 }
77 };
78
Jorge Canizales34b26292015-06-02 02:11:09 -070079 RTGPoint *point = [RTGPoint message];
80 point.latitude = 409146138;
81 point.longitude = -746188906;
82
Jorge Canizales3aed7172015-06-04 22:56:21 -070083 [client getFeatureWithRequest:point handler:handler];
84 [client getFeatureWithRequest:[RTGPoint message] handler:handler];
Jorge Canizales34b26292015-06-02 02:11:09 -070085}
86
87@end
88
Jorge Canizales3fda5482015-06-05 12:05:00 -070089
Jorge Canizales34b26292015-06-02 02:11:09 -070090#pragma mark List Features
91
Jorge Canizales4694cdb2015-06-04 23:06:13 -070092// Run the listFeatures demo. Calls listFeatures with a rectangle containing all of the features in
93// the pre-generated database. Prints each response as it comes in.
94
Jorge Canizales34b26292015-06-02 02:11:09 -070095@interface ListFeaturesViewController : UIViewController
96@end
97
98@implementation ListFeaturesViewController
99
100- (void)viewDidLoad {
101 [super viewDidLoad];
Jorge Canizales4694cdb2015-06-04 23:06:13 -0700102
103 RTGRouteGuide *client = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
104
105 RTGRectangle *rectangle = [RTGRectangle message];
Jorge Canizalesc9885952015-06-05 17:41:00 -0700106 rectangle.lo.latitude = 405E6;
107 rectangle.lo.longitude = -750E6;
108 rectangle.hi.latitude = 410E6;
109 rectangle.hi.longitude = -745E6;
Jorge Canizales4694cdb2015-06-04 23:06:13 -0700110
Jorge Canizalesc9885952015-06-05 17:41:00 -0700111 NSLog(@"Looking for features between %@ and %@", rectangle.lo, rectangle.hi);
Jorge Canizales4694cdb2015-06-04 23:06:13 -0700112 [client listFeaturesWithRequest:rectangle handler:^(BOOL done, RTGFeature *response, NSError *error) {
113 if (response) {
Jorge Canizalesc9885952015-06-05 17:41:00 -0700114 NSLog(@"Found feature at %@ called %@.", response.location, response.name);
Jorge Canizales4694cdb2015-06-04 23:06:13 -0700115 } else if (error) {
116 NSLog(@"RPC error: %@", error);
117 }
118 }];
Jorge Canizales34b26292015-06-02 02:11:09 -0700119}
120
121@end
122
Jorge Canizales3fda5482015-06-05 12:05:00 -0700123
Jorge Canizales34b26292015-06-02 02:11:09 -0700124#pragma mark Record Route
125
126@interface RecordRouteViewController : UIViewController
127@end
128
129@implementation RecordRouteViewController
130
131- (void)viewDidLoad {
132 [super viewDidLoad];
133 // Do any additional setup after loading the view.
134}
135
136@end
137
Jorge Canizales3fda5482015-06-05 12:05:00 -0700138
Jorge Canizales34b26292015-06-02 02:11:09 -0700139#pragma mark Route Chat
140
141@interface RouteChatViewController : UIViewController
142@end
143
144@implementation RouteChatViewController
145
146- (void)viewDidLoad {
147 [super viewDidLoad];
148 // Do any additional setup after loading the view.
149}
150
151@end