Skip to content

Commit 6290568

Browse files
chore: Update Maps and Places samples from CocoaPods (#66)
1 parent 6ac35f3 commit 6290568

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+871
-432
lines changed

GoogleMaps/GoogleMapsDemos.xcodeproj/project.pbxproj

Lines changed: 258 additions & 225 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2020 Google LLC. All rights reserved.
3+
*
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6+
* file except in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under
11+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
* ANY KIND, either express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#import <UIKit/UIKit.h>
17+
18+
@interface CloudBasedMapStylingViewController : UIViewController
19+
@end
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright 2020 Google LLC. All rights reserved.
3+
*
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6+
* file except in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under
11+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
* ANY KIND, either express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#import "GoogleMapsDemos/BetaSamples/CloudBasedMapStylingViewController.h"
17+
#import <GoogleMaps/GoogleMaps.h>
18+
19+
20+
static NSString *const kMapIDRetro = @"13564581852493597319";
21+
static NSString *const kMapIDDemo = @"11153850776783499500";
22+
23+
/** Demonstrate basic usage of the Cloud Styling feature. */
24+
@implementation CloudBasedMapStylingViewController {
25+
GMSMapView *_mapView;
26+
NSMutableArray<NSString *> *_mapIDStrings;
27+
}
28+
29+
- (void)viewDidLoad {
30+
[super viewDidLoad];
31+
32+
_mapIDStrings = [[NSMutableArray alloc] init];
33+
[_mapIDStrings addObject:kMapIDRetro];
34+
[_mapIDStrings addObject:kMapIDDemo];
35+
36+
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
37+
longitude:151.2086
38+
zoom:12];
39+
40+
_mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
41+
self.view = _mapView;
42+
43+
UIBarButtonItem *styleButton = [[UIBarButtonItem alloc] initWithTitle:@"Style Map"
44+
style:UIBarButtonItemStylePlain
45+
target:self
46+
action:@selector(changeMapID:)];
47+
self.navigationItem.rightBarButtonItem = styleButton;
48+
}
49+
50+
51+
/** Re-create the map view with the specified mapID. */
52+
- (void)updateMapWithExistingMapIDString:(nonnull NSString *)mapIDString {
53+
GMSMapID *mapID = [GMSMapID mapIDWithIdentifier:mapIDString];
54+
_mapView = [GMSMapView mapWithFrame:CGRectZero mapID:mapID camera:_mapView.camera];
55+
self.view = _mapView;
56+
}
57+
58+
/** Add the new map ID to the list of selectable IDs and update the map to use it. */
59+
- (void)updateMapWithNewMapIDString:(NSString *)mapIDString {
60+
if (mapIDString.length > 0) {
61+
[_mapIDStrings addObject:mapIDString];
62+
[self updateMapWithExistingMapIDString:mapIDString];
63+
}
64+
}
65+
66+
/** Ask the user for a new map ID to add to the list. */
67+
- (void)showAddMapIDAlert {
68+
UIAlertController *alertController =
69+
[UIAlertController alertControllerWithTitle:@"Add a new map ID"
70+
message:nil
71+
preferredStyle:UIAlertControllerStyleAlert];
72+
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
73+
textField.placeholder = @"Map ID";
74+
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
75+
}];
76+
__weak __typeof__(self) weakSelf = self;
77+
[alertController
78+
addAction:[UIAlertAction actionWithTitle:@"OK"
79+
style:UIAlertActionStyleDefault
80+
handler:^(UIAlertAction *action) {
81+
__typeof__(self) strongSelf = weakSelf;
82+
if (strongSelf) {
83+
NSString *mapIDString =
84+
alertController.textFields[0].text;
85+
[strongSelf updateMapWithNewMapIDString:mapIDString];
86+
}
87+
}]];
88+
[self presentViewController:alertController animated:YES completion:nil];
89+
}
90+
91+
/** Return an action that sets the appearance of the map to the mapID. */
92+
- (UIAlertAction *_Nonnull)alertActionForMapIDString:(nonnull NSString *)mapID {
93+
__weak __typeof__(self) weakSelf = self;
94+
return [UIAlertAction actionWithTitle:mapID
95+
style:UIAlertActionStyleDefault
96+
handler:^(UIAlertAction *_Nonnull action) {
97+
__typeof__(self) strongSelf = weakSelf;
98+
if (strongSelf) {
99+
[strongSelf updateMapWithExistingMapIDString:mapID];
100+
}
101+
}];
102+
}
103+
104+
/** Return an action which prompts an alert to type in a new map ID. */
105+
- (UIAlertAction *_Nonnull)alertActionToAddMapID {
106+
__weak __typeof__(self) weakSelf = self;
107+
return [UIAlertAction actionWithTitle:@"Add a new Map ID"
108+
style:UIAlertActionStyleDestructive
109+
handler:^(UIAlertAction *_Nonnull action) {
110+
__typeof__(self) strongSelf = weakSelf;
111+
if (strongSelf) {
112+
[strongSelf showAddMapIDAlert];
113+
}
114+
}];
115+
}
116+
117+
118+
/** Bring up a selection list of existing Map IDs, and the option to add a new one. */
119+
- (void)changeMapID:(UIBarButtonItem *)sender {
120+
UIAlertController *alert =
121+
[UIAlertController alertControllerWithTitle:@"Select Map ID"
122+
message:@"Change the look of the map with a map ID"
123+
preferredStyle:UIAlertControllerStyleActionSheet];
124+
[alert addAction:[self alertActionToAddMapID]];
125+
126+
// Lists the existing Map IDs for selection.
127+
for (NSString *mapIDString in _mapIDStrings) {
128+
[alert addAction:[self alertActionForMapIDString:mapIDString]];
129+
}
130+
131+
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel"
132+
style:UIAlertActionStyleCancel
133+
handler:nil]];
134+
alert.popoverPresentationController.barButtonItem = sender;
135+
[self presentViewController:alert animated:YES completion:nil];
136+
}
137+
138+
@end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2020 Google LLC. All rights reserved.
3+
*
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6+
* file except in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under
11+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
* ANY KIND, either express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#import <UIKit/UIKit.h>
17+
18+
@interface CollidingMarkersViewController : UIViewController
19+
@end
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright 2020 Google LLC. All rights reserved.
3+
*
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6+
* file except in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under
11+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
* ANY KIND, either express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#import "GoogleMapsDemos/BetaSamples/CollidingMarkersViewController.h"
17+
18+
#import <GoogleMaps/GoogleMaps.h>
19+
20+
const CLLocationCoordinate2D kSeattleCoordinates = {.latitude = 47.6098, .longitude = -122.34};
21+
22+
/**
23+
* Demonstrates basic usage of the marker collision feature.
24+
* Try zooming in/out, and dragging around different colored markers.
25+
*/
26+
@implementation CollidingMarkersViewController {
27+
GMSMapView *_mapView;
28+
}
29+
30+
/**
31+
* These are the "standard" markers - they will show up no matter what, and they don't have
32+
* intersection or collision checking with map labels or other markers.
33+
*/
34+
- (GMSMarker *)createNonCollidingMarkerWithLatitude:(CLLocationDegrees)latitude
35+
longitude:(CLLocationDegrees)longitude
36+
zIndex:(int)zIndex {
37+
GMSMarker *marker = [[GMSMarker alloc] init];
38+
marker.title = @"Non-Colliding";
39+
marker.snippet = [NSString stringWithFormat:@"zIndex: %d", zIndex];
40+
marker.zIndex = zIndex;
41+
marker.draggable = YES;
42+
marker.position = CLLocationCoordinate2DMake(latitude, longitude);
43+
marker.icon = [GMSMarker markerImageWithColor:UIColor.blueColor];
44+
// No need for setting collision behavior since it's the default behavior, but setting to
45+
// GMSCollisionBehaviorRequired also works.
46+
return marker;
47+
}
48+
49+
/**
50+
* These markers will show up if they aren't intersecting anything higher priority (required or
51+
* higher zIndex optional markers), and they will hide intersecting normal map labels or lower
52+
* zIndex optional markers.
53+
*
54+
* Note: While an optional marker is in the middle of being dragged, it is considered higher
55+
* priority than other optional markers, regardless of zIndex. But once it has been dropped,
56+
* priority goes back to zIndices.
57+
*/
58+
- (GMSMarker *)createOptionalMarkerWithLatitude:(CLLocationDegrees)latitude
59+
longitude:(CLLocationDegrees)longitude
60+
zIndex:(int)zIndex {
61+
GMSMarker *marker = [[GMSMarker alloc] init];
62+
marker.title = @"Optional";
63+
marker.snippet = [NSString stringWithFormat:@"zIndex: %d", zIndex];
64+
marker.zIndex = zIndex;
65+
marker.draggable = YES;
66+
marker.position = CLLocationCoordinate2DMake(latitude, longitude);
67+
marker.icon = [GMSMarker markerImageWithColor:UIColor.greenColor];
68+
marker.collisionBehavior = GMSCollisionBehaviorOptionalAndHidesLowerPriority;
69+
return marker;
70+
}
71+
72+
/**
73+
* These markers will always show up, and they will hide intersecting normal map labels or
74+
* optional markers.
75+
*/
76+
- (GMSMarker *)createRequiredMarkerWithLatitude:(CLLocationDegrees)latitude
77+
longitude:(CLLocationDegrees)longitude
78+
zIndex:(int)zIndex {
79+
GMSMarker *marker = [[GMSMarker alloc] init];
80+
marker.title = @"Required";
81+
marker.snippet = [NSString stringWithFormat:@"zIndex: %d", zIndex];
82+
marker.zIndex = zIndex;
83+
marker.draggable = YES;
84+
marker.position = CLLocationCoordinate2DMake(latitude, longitude);
85+
marker.collisionBehavior = GMSCollisionBehaviorRequiredAndHidesOptional;
86+
return marker;
87+
}
88+
89+
- (void)viewDidLoad {
90+
[super viewDidLoad];
91+
92+
GMSCameraPosition *camera = [GMSCameraPosition cameraWithTarget:kSeattleCoordinates zoom:16];
93+
94+
_mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
95+
_mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
96+
[self.view addSubview:_mapView];
97+
98+
CLLocationCoordinate2D requiredCollidingFirstPosition = {
99+
.latitude = kSeattleCoordinates.latitude - 0.002,
100+
.longitude = kSeattleCoordinates.longitude - 0.003};
101+
CLLocationCoordinate2D requiredNonCollidingFirstPosition = {
102+
.latitude = kSeattleCoordinates.latitude, .longitude = kSeattleCoordinates.longitude - 0.003};
103+
CLLocationCoordinate2D optionalFirstPosition = {.latitude = kSeattleCoordinates.latitude - 0.001,
104+
.longitude = kSeattleCoordinates.longitude};
105+
106+
CLLocationDegrees markerSpacing = 0.004;
107+
int markerCount = 0;
108+
109+
for (int i = 0; i < 2; i++) {
110+
for (int j = 0; j < 2; j++) {
111+
GMSMarker *nonColliding =
112+
[self createNonCollidingMarkerWithLatitude:requiredNonCollidingFirstPosition.latitude +
113+
(i * markerSpacing)
114+
longitude:requiredNonCollidingFirstPosition.longitude +
115+
(j * markerSpacing)
116+
zIndex:markerCount++];
117+
nonColliding.map = _mapView;
118+
GMSMarker *optional = [self
119+
createOptionalMarkerWithLatitude:optionalFirstPosition.latitude + (i * markerSpacing)
120+
longitude:optionalFirstPosition.longitude + (j * markerSpacing)
121+
zIndex:markerCount++];
122+
optional.map = _mapView;
123+
GMSMarker *required =
124+
[self createRequiredMarkerWithLatitude:requiredCollidingFirstPosition.latitude +
125+
(i * markerSpacing)
126+
longitude:requiredCollidingFirstPosition.longitude +
127+
(j * markerSpacing)
128+
zIndex:markerCount++];
129+
required.map = _mapView;
130+
}
131+
}
132+
}
133+
@end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2020 Google LLC. All rights reserved.
3+
*
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6+
* file except in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under
11+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
* ANY KIND, either express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#import <Foundation/Foundation.h>
17+
18+
#import "GoogleMapsDemos/Samples/Samples.h"
19+
20+
@interface Samples (Beta)
21+
22+
+ (NSArray *)betaDemos;
23+
24+
@end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2020 Google LLC. All rights reserved.
3+
*
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6+
* file except in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under
11+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
* ANY KIND, either express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#import "GoogleMapsDemos/BetaSamples/Samples+Beta.h"
17+
18+
#import "GoogleMapsDemos/BetaSamples/CloudBasedMapStylingViewController.h"
19+
#import "GoogleMapsDemos/BetaSamples/CollidingMarkersViewController.h"
20+
#import "GoogleMapsDemos/BetaSamples/StampedPolylinesViewController.h"
21+
22+
@implementation Samples (Beta)
23+
24+
/** Returns the array of Early-Access-Partner-only samples. */
25+
+ (NSArray *)betaDemos {
26+
return @[
27+
[self newDemo:[CloudBasedMapStylingViewController class]
28+
withTitle:@"Cloud-based Map Styling"
29+
andDescription:nil],
30+
[self newDemo:[StampedPolylinesViewController class]
31+
withTitle:@"Stamped Polylines"
32+
andDescription:nil],
33+
[self newDemo:[CollidingMarkersViewController class]
34+
withTitle:@"Colliding Markers"
35+
andDescription:nil],
36+
];
37+
}
38+
39+
@end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2020 Google LLC. All rights reserved.
3+
*
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6+
* file except in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under
11+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
* ANY KIND, either express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#import <UIKit/UIKit.h>
17+
18+
@interface StampedPolylinesViewController : UIViewController
19+
@end

0 commit comments

Comments
 (0)