Skip to content

Commit

Permalink
chore: Update Maps and Places samples from CocoaPods (#171)
Browse files Browse the repository at this point in the history
* chore: Update Maps and Places samples from CocoaPods

* chore: update snippets and tutorials to 8.0.0

---------

Co-authored-by: Angela Yu <[email protected]>
  • Loading branch information
googlemaps-bot and wangela authored Jun 2, 2023
1 parent 683fb61 commit ac61f0d
Show file tree
Hide file tree
Showing 33 changed files with 502 additions and 417 deletions.
338 changes: 173 additions & 165 deletions GoogleMaps-Swift/GoogleMapsSwiftDemos.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ extension CLLocationCoordinate2D {
// Victoria, Australia
static let victoria = CLLocationCoordinate2D(latitude: -37.81969, longitude: 144.966085)
static let newYork = CLLocationCoordinate2D(latitude: 40.761388, longitude: -73.978133)
static let mountainSceneLocation = CLLocationCoordinate2D(
latitude: -33.732022, longitude: 150.312114)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import GoogleMaps
import UIKit

class FixedPanoramaViewController: UIViewController {

override func loadView() {
let panoramaView = GMSPanoramaView(frame: .zero)
panoramaView.moveNearCoordinate(.newYork)
panoramaView.moveNearCoordinate(.mountainSceneLocation)
panoramaView.camera = GMSPanoramaCamera(heading: 180, pitch: -10, zoom: 0)
panoramaView.orientationGestures = false
panoramaView.navigationGestures = false
Expand Down
4 changes: 2 additions & 2 deletions GoogleMaps-Swift/Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://github.com/CocoaPods/Specs.git'

target 'GoogleMapsSwiftDemos' do
platform :ios, '13.0'
pod 'GoogleMaps', '= 7.4.0'
platform :ios, '14.0'
pod 'GoogleMaps', '= 8.0.0'
end
254 changes: 131 additions & 123 deletions GoogleMaps/GoogleMapsDemos.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 30 additions & 33 deletions GoogleMaps/GoogleMapsDemos/Samples/MapLayerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

@implementation MapLayerViewController {
GMSMapView *_mapView;
BOOL _rotating;
}

- (void)viewDidLoad {
Expand Down Expand Up @@ -47,43 +48,39 @@ - (void)didTapMyLocation {
if (!location || !CLLocationCoordinate2DIsValid(location.coordinate)) {
return;
}

_mapView.layer.cameraLatitude = location.coordinate.latitude;
_mapView.layer.cameraLongitude = location.coordinate.longitude;
_mapView.layer.cameraBearing = 0.0;

// Access the GMSMapLayer directly to modify the following properties with a specified timing
// function and duration.
GMSCameraPosition *camera =
[[GMSCameraPosition alloc] initWithTarget:location.coordinate
zoom:_mapView.camera.zoom
bearing:0.0
viewingAngle:_mapView.camera.viewingAngle];
CAMediaTimingFunction *curve =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
CABasicAnimation *animation;

animation = [CABasicAnimation animationWithKeyPath:kGMSLayerCameraLatitudeKey];
animation.duration = 2.0f;
animation.timingFunction = curve;
animation.toValue = @(location.coordinate.latitude);
[_mapView.layer addAnimation:animation forKey:kGMSLayerCameraLatitudeKey];
// Animate to the marker
[CATransaction begin];
[CATransaction setAnimationDuration:2.0f]; // 2 second animation
[CATransaction setAnimationTimingFunction:curve];
[CATransaction setCompletionBlock:^{
if (_rotating) { // Animation was interrupted by orientation change.
[CATransaction
setDisableActions:true]; // Disable animation to avoid interruption from rotation.
[_mapView animateToCameraPosition:camera];
}
}];

animation = [CABasicAnimation animationWithKeyPath:kGMSLayerCameraLongitudeKey];
animation.duration = 2.0f;
animation.timingFunction = curve;
animation.toValue = @(location.coordinate.longitude);
[_mapView.layer addAnimation:animation forKey:kGMSLayerCameraLongitudeKey];

animation = [CABasicAnimation animationWithKeyPath:kGMSLayerCameraBearingKey];
animation.duration = 2.0f;
animation.timingFunction = curve;
animation.toValue = @0.0;
[_mapView.layer addAnimation:animation forKey:kGMSLayerCameraBearingKey];
[_mapView animateToCameraPosition:camera];
[CATransaction commit];
}

// Fly out to the minimum zoom and then zoom back to the current zoom!
CGFloat zoom = _mapView.camera.zoom;
NSArray *keyValues = @[ @(zoom), @(kGMSMinZoomLevel), @(zoom) ];
CAKeyframeAnimation *keyFrameAnimation =
[CAKeyframeAnimation animationWithKeyPath:kGMSLayerCameraZoomLevelKey];
keyFrameAnimation.duration = 2.0f;
keyFrameAnimation.values = keyValues;
[_mapView.layer addAnimation:keyFrameAnimation forKey:kGMSLayerCameraZoomLevelKey];
- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
_rotating = true;
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator
animateAlongsideTransition:nil
completion:^(
id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
_rotating = false;
}];
}

@end
28 changes: 24 additions & 4 deletions GoogleMaps/GoogleMapsDemos/Samples/MarkerEventsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@implementation MarkerEventsViewController {
GMSMapView *_mapView;
GMSMarker *_melbourneMarker;
BOOL _rotating;
}

- (void)viewDidLoad {
Expand Down Expand Up @@ -54,14 +55,21 @@ - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
}

- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
// Animate to the marker
[CATransaction begin];
[CATransaction setAnimationDuration:3.f]; // 3 second animation

GMSCameraPosition *camera = [[GMSCameraPosition alloc] initWithTarget:marker.position
zoom:8
bearing:50
viewingAngle:60];
// Animate to the marker
[CATransaction begin];
[CATransaction setAnimationDuration:3.f]; // 3 second animation
[CATransaction setCompletionBlock:^{
if (_rotating) { // Animation was interrupted by orientation change.
[CATransaction
setDisableActions:true]; // Disable animation to avoid interruption from rotation.
[_mapView animateToCameraPosition:camera];
}
}];

[mapView animateToCameraPosition:camera];
[CATransaction commit];

Expand All @@ -75,4 +83,16 @@ - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
return YES;
}

- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
_rotating = true;
[coordinator
animateAlongsideTransition:nil
completion:^(
id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
_rotating = false;
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
static const double kSeattleLongitudeDegrees = -122.3410462;
static const double kZoom = 14;
static const double kStrokeWidth = 20;
/* The following encoded path was constructed by using the Directions API.
* This is the path from the Space Needle to Paramount Theatre, with the mode of transport
* set to walking.
* Please see the documentation https://developers.google.com/maps/documentation/directions
* for more detail.
*/
static NSString *const kEncodedPathForWalkingDirections =
@"ezsaHxkwiVLc@FQ?G@G@GDKBEPED?@@B@FOJSOUDIZk@?cB?w@?iA@yLAs@?IB?Ae@@_A?sACoA?EB??e@?u@A}A@{@`@"
@"EBGv@_C\\aA?M?G@WHCFB|@kCRm@DQ?EDB@FZP?E@_@CC?oA?O\\i@j@mAN[DWd@GIq@BA?CBUVcAhA_CLUBDL_@@Bf@"
@"eA`@o@|@iBCCRa@DD^aAf@{@`@}@Xc@GIVc@DDj@iANe@x@cBHUACRYNPZQHLDFDCVSB?CGKYHGr@s@r@g@v@o@"
@"GUVSBC@FDJJK";

@implementation StampedPolylinesViewController

Expand All @@ -37,7 +48,17 @@ - (void)viewDidLoad {
map.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:map];

// Make a texture stamped polyline.
[self addTextureStampedPolylineToMap:map];
[self addGradientTextureStampedPolylineToMap:map];
[self addSpriteWalkingDotStampedPolylineToMap:map];
}

/**
* Creates a texture stamped polyline and adds it to the supplied map.
*
* @param map The map to add the polyline to.
*/
- (void)addTextureStampedPolylineToMap:(GMSMapView *)map {
GMSMutablePath *path = [GMSMutablePath path];
[path addLatitude:kSeattleLatitudeDegrees + 0.003 longitude:kSeattleLongitudeDegrees - 0.003];
[path addLatitude:kSeattleLatitudeDegrees - 0.005 longitude:kSeattleLongitudeDegrees - 0.005];
Expand All @@ -51,8 +72,14 @@ - (void)viewDidLoad {
texturePolyline.map = map;
texturePolyline.strokeWidth = kStrokeWidth;
texturePolyline.spans = @[ [GMSStyleSpan spanWithStyle:solidStroke] ];
}

// Make a gradient texture polyline.
/**
* Creates a texture stamped polyline with gradient background and adds it to the supplied map.
*
* @param map The map to add the polyline to.
*/
- (void)addGradientTextureStampedPolylineToMap:(GMSMapView *)map {
GMSMutablePath *texturePath = [GMSMutablePath path];
[texturePath addLatitude:kSeattleLatitudeDegrees - 0.012 longitude:kSeattleLongitudeDegrees];
[texturePath addLatitude:kSeattleLatitudeDegrees - 0.012
Expand All @@ -71,6 +98,23 @@ - (void)viewDidLoad {
gradientTexturePolyline.map = map;
}

/**
* Creates a sprite stamped polyline, using walking dots as the sprite, to the supplied map.
*
* @param map The map to add the polyline to.
*/
- (void)addSpriteWalkingDotStampedPolylineToMap:(GMSMapView *)map {
GMSPath *path = [GMSPath pathFromEncodedPath:kEncodedPathForWalkingDirections];

UIImage *_Nonnull stamp = (UIImage *_Nonnull)[UIImage imageNamed:@"walking_dot.png"];
GMSStrokeStyle *stroke = [GMSStrokeStyle solidColor:[UIColor redColor]];
stroke.stampStyle = [GMSSpriteStyle spriteStyleWithImage:stamp];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.map = map;
polyline.strokeWidth = kStrokeWidth;
polyline.spans = @[ [GMSStyleSpan spanWithStyle:stroke] ];
}

@end

NS_ASSUME_NONNULL_END
7 changes: 7 additions & 0 deletions GoogleMaps/GoogleMapsDemos/Samples/TileLayerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ - (void)viewDidLoad {
[self didChangeSwitcher];
}

- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
// Re-show level picker.
self.navigationItem.titleView = nil;
self.navigationItem.titleView = _switcher;
}

- (void)didChangeSwitcher {
NSString *title = [_switcher titleForSegmentAtIndex:_switcher.selectedSegmentIndex];
NSInteger floor = [title integerValue];
Expand Down
4 changes: 2 additions & 2 deletions GoogleMaps/Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://github.com/CocoaPods/Specs.git'

target 'GoogleMapsDemos' do
platform :ios, '13.0'
pod 'GoogleMaps', '= 7.4.0'
platform :ios, '14.0'
pod 'GoogleMaps', '= 8.0.0'
end
Loading

0 comments on commit ac61f0d

Please sign in to comment.