Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 37 | static NSString * const kHostAddress = @"http://localhost:50051"; |
| 38 | |
Jorge Canizales | c988595 | 2015-06-05 17:41:00 -0700 | [diff] [blame^] | 39 | // 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 Canizales | 3fda548 | 2015-06-05 12:05:00 -0700 | [diff] [blame] | 53 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 54 | #pragma mark Get Feature |
| 55 | |
Jorge Canizales | 3aed717 | 2015-06-04 22:56:21 -0700 | [diff] [blame] | 56 | // 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 Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 59 | @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 Canizales | 3aed717 | 2015-06-04 22:56:21 -0700 | [diff] [blame] | 69 | 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 Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 79 | RTGPoint *point = [RTGPoint message]; |
| 80 | point.latitude = 409146138; |
| 81 | point.longitude = -746188906; |
| 82 | |
Jorge Canizales | 3aed717 | 2015-06-04 22:56:21 -0700 | [diff] [blame] | 83 | [client getFeatureWithRequest:point handler:handler]; |
| 84 | [client getFeatureWithRequest:[RTGPoint message] handler:handler]; |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @end |
| 88 | |
Jorge Canizales | 3fda548 | 2015-06-05 12:05:00 -0700 | [diff] [blame] | 89 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 90 | #pragma mark List Features |
| 91 | |
Jorge Canizales | 4694cdb | 2015-06-04 23:06:13 -0700 | [diff] [blame] | 92 | // 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 Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 95 | @interface ListFeaturesViewController : UIViewController |
| 96 | @end |
| 97 | |
| 98 | @implementation ListFeaturesViewController |
| 99 | |
| 100 | - (void)viewDidLoad { |
| 101 | [super viewDidLoad]; |
Jorge Canizales | 4694cdb | 2015-06-04 23:06:13 -0700 | [diff] [blame] | 102 | |
| 103 | RTGRouteGuide *client = [[RTGRouteGuide alloc] initWithHost:kHostAddress]; |
| 104 | |
| 105 | RTGRectangle *rectangle = [RTGRectangle message]; |
Jorge Canizales | c988595 | 2015-06-05 17:41:00 -0700 | [diff] [blame^] | 106 | rectangle.lo.latitude = 405E6; |
| 107 | rectangle.lo.longitude = -750E6; |
| 108 | rectangle.hi.latitude = 410E6; |
| 109 | rectangle.hi.longitude = -745E6; |
Jorge Canizales | 4694cdb | 2015-06-04 23:06:13 -0700 | [diff] [blame] | 110 | |
Jorge Canizales | c988595 | 2015-06-05 17:41:00 -0700 | [diff] [blame^] | 111 | NSLog(@"Looking for features between %@ and %@", rectangle.lo, rectangle.hi); |
Jorge Canizales | 4694cdb | 2015-06-04 23:06:13 -0700 | [diff] [blame] | 112 | [client listFeaturesWithRequest:rectangle handler:^(BOOL done, RTGFeature *response, NSError *error) { |
| 113 | if (response) { |
Jorge Canizales | c988595 | 2015-06-05 17:41:00 -0700 | [diff] [blame^] | 114 | NSLog(@"Found feature at %@ called %@.", response.location, response.name); |
Jorge Canizales | 4694cdb | 2015-06-04 23:06:13 -0700 | [diff] [blame] | 115 | } else if (error) { |
| 116 | NSLog(@"RPC error: %@", error); |
| 117 | } |
| 118 | }]; |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @end |
| 122 | |
Jorge Canizales | 3fda548 | 2015-06-05 12:05:00 -0700 | [diff] [blame] | 123 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 124 | #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 Canizales | 3fda548 | 2015-06-05 12:05:00 -0700 | [diff] [blame] | 138 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 139 | #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 |