Skip to content

Commit

Permalink
Added requesting directions sample
Browse files Browse the repository at this point in the history
  • Loading branch information
shu223 committed Sep 24, 2013
1 parent ce05b5a commit b1611c4
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ A sample of Sprite Kit using SKView, SKScene, SKSpriteNode, SKAction.
![](https://qiita-image-store.s3.amazonaws.com/0/3180/98fcfb76-5ac4-6c3b-cfca-a008790c948a.png)


###Map Directions

Requesting and draw directions using MKDirections, MKDirectionsResponse and MKPolylineRenderer.

![mapdirection_.png](https://qiita-image-store.s3.amazonaws.com/0/3180/3fe4c6f3-4d3d-0fd2-92ee-e5ffcac51b8e.png)

###Motion Effects (Parallax)

Parallax effect using UIMotionEffect.
Expand Down
20 changes: 20 additions & 0 deletions iOS7Sampler.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
8A43D5DD17F187BE005E8BE8 /* SpriteKitViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8A43D5DB17F187BE005E8BE8 /* SpriteKitViewController.xib */; };
8A43D5E017F187D9005E8BE8 /* SampleScene.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A43D5DF17F187D9005E8BE8 /* SampleScene.m */; };
8A6DBC6817F18814004311FE /* SpriteKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A6DBC6717F18814004311FE /* SpriteKit.framework */; };
8A6DBC6C17F193FB004311FE /* MapOverlaysViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A6DBC6A17F193FB004311FE /* MapOverlaysViewController.m */; };
8A6DBC6D17F193FB004311FE /* MapOverlaysViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8A6DBC6B17F193FB004311FE /* MapOverlaysViewController.xib */; };
8A6DBC7117F19718004311FE /* MapDirectionsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A6DBC6F17F19718004311FE /* MapDirectionsViewController.m */; };
8A6DBC7217F19718004311FE /* MapDirectionsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8A6DBC7017F19718004311FE /* MapDirectionsViewController.xib */; };
8A7BF1C117ED384C004EF216 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A7BF1C017ED384C004EF216 /* Foundation.framework */; };
8A7BF1C317ED384C004EF216 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A7BF1C217ED384C004EF216 /* CoreGraphics.framework */; };
8A7BF1C517ED384C004EF216 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A7BF1C417ED384C004EF216 /* UIKit.framework */; };
Expand Down Expand Up @@ -133,6 +137,12 @@
8A43D5DE17F187D9005E8BE8 /* SampleScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SampleScene.h; sourceTree = "<group>"; };
8A43D5DF17F187D9005E8BE8 /* SampleScene.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SampleScene.m; sourceTree = "<group>"; };
8A6DBC6717F18814004311FE /* SpriteKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SpriteKit.framework; path = System/Library/Frameworks/SpriteKit.framework; sourceTree = SDKROOT; };
8A6DBC6917F193FB004311FE /* MapOverlaysViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapOverlaysViewController.h; sourceTree = "<group>"; };
8A6DBC6A17F193FB004311FE /* MapOverlaysViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapOverlaysViewController.m; sourceTree = "<group>"; };
8A6DBC6B17F193FB004311FE /* MapOverlaysViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MapOverlaysViewController.xib; sourceTree = "<group>"; };
8A6DBC6E17F19718004311FE /* MapDirectionsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapDirectionsViewController.h; sourceTree = "<group>"; };
8A6DBC6F17F19718004311FE /* MapDirectionsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapDirectionsViewController.m; sourceTree = "<group>"; };
8A6DBC7017F19718004311FE /* MapDirectionsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MapDirectionsViewController.xib; sourceTree = "<group>"; };
8A7BF1BD17ED384B004EF216 /* iOS7Sampler.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOS7Sampler.app; sourceTree = BUILT_PRODUCTS_DIR; };
8A7BF1C017ED384C004EF216 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
8A7BF1C217ED384C004EF216 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -388,6 +398,12 @@
8A43D5DB17F187BE005E8BE8 /* SpriteKitViewController.xib */,
8A43D5DE17F187D9005E8BE8 /* SampleScene.h */,
8A43D5DF17F187D9005E8BE8 /* SampleScene.m */,
8A6DBC6917F193FB004311FE /* MapOverlaysViewController.h */,
8A6DBC6A17F193FB004311FE /* MapOverlaysViewController.m */,
8A6DBC6B17F193FB004311FE /* MapOverlaysViewController.xib */,
8A6DBC6E17F19718004311FE /* MapDirectionsViewController.h */,
8A6DBC6F17F19718004311FE /* MapDirectionsViewController.m */,
8A6DBC7017F19718004311FE /* MapDirectionsViewController.xib */,
);
path = SampleViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -559,6 +575,7 @@
buildActionMask = 2147483647;
files = (
8A7BF36D17ED5BB1004EF216 /* m17@2x.png in Resources */,
8A6DBC7217F19718004311FE /* MapDirectionsViewController.xib in Resources */,
8A7BF36317ED5BB1004EF216 /* m7@2x.png in Resources */,
8A7BF36417ED5BB1004EF216 /* m8@2x.png in Resources */,
8A7BF37717ED5BB1004EF216 /* m27@2x.png in Resources */,
Expand Down Expand Up @@ -610,6 +627,7 @@
8A7BF36617ED5BB1004EF216 /* m10@2x.png in Resources */,
8A7BF1D417ED384C004EF216 /* Main.storyboard in Resources */,
8A7BF3A617ED7F5D004EF216 /* stage_5@2x.png in Resources */,
8A6DBC6D17F193FB004311FE /* MapOverlaysViewController.xib in Resources */,
8A7BF37C17ED5BB1004EF216 /* m32@2x.png in Resources */,
8A7BF36F17ED5BB1004EF216 /* m19@2x.png in Resources */,
8A7BF36217ED5BB1004EF216 /* m6@2x.png in Resources */,
Expand Down Expand Up @@ -643,12 +661,14 @@
8A7BF39417ED7EF7004EF216 /* MotionEffectViewController.m in Sources */,
8A43D5B117F11BCA005E8BE8 /* MapSnapshotViewController.m in Sources */,
8A7BF3BB17ED8B43004EF216 /* HUTransitionAnimator.m in Sources */,
8A6DBC7117F19718004311FE /* MapDirectionsViewController.m in Sources */,
8A7BF38817ED6882004EF216 /* ActivityTypesViewController.m in Sources */,
8A7BF3AF17ED8A9E004EF216 /* CustomTransitionViewController.m in Sources */,
8A7BF1D717ED384C004EF216 /* MasterViewController.m in Sources */,
8A7BF1CD17ED384C004EF216 /* main.m in Sources */,
8A7BF29217ED4C9F004EF216 /* DynamicBehaviorsViewController.m in Sources */,
8A43D5B817F11E72005E8BE8 /* SVProgressHUD.m in Sources */,
8A6DBC6C17F193FB004311FE /* MapOverlaysViewController.m in Sources */,
8A43D5D417F12307005E8BE8 /* ZBFallenBricksAnimator.m in Sources */,
8A043B1817F0D34200DA84E9 /* Map3DViewController.m in Sources */,
8A7BF3BD17ED8B43004EF216 /* HUTransitionHorizontalLinesAnimator.m in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions iOS7Sampler/MasterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ - (void)viewDidLoad
kItemKeyClassPrefix: @"SpriteKit",
},

// Map Directions
@{kItemKeyTitle: @"Map Directions",
kItemKeyDescription: @"Requesting and draw directions using MKDirections, MKDirectionsResponse and MKPolylineRenderer.",
kItemKeyClassPrefix: @"MapDirections",
},

// Motion Effect
@{kItemKeyTitle: @"Motion Effects (Parallax)",
kItemKeyDescription: @"Parallax effect using UIMotionEffect",
Expand Down
13 changes: 13 additions & 0 deletions iOS7Sampler/SampleViewControllers/MapDirectionsViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// MapDirectionsViewController.h
// iOS7Sampler
//
// Created by shuichi on 9/24/13.
// Copyright (c) 2013 Shuichi Tsutsumi. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MapDirectionsViewController : UIViewController

@end
122 changes: 122 additions & 0 deletions iOS7Sampler/SampleViewControllers/MapDirectionsViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//
// MapDirectionsViewController.m
// iOS7Sampler
//
// Created by shuichi on 9/24/13.
// Copyright (c) 2013 Shuichi Tsutsumi. All rights reserved.
//

#import "MapDirectionsViewController.h"
#import <MapKit/MapKit.h>
#import "SVProgressHUD.h"


@interface MapDirectionsViewController ()
<MKMapViewDelegate>
@property (nonatomic, weak) IBOutlet MKMapView *mapView;
@end


@implementation MapDirectionsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(37.501364, -122.182817);
MKCoordinateSpan span = MKCoordinateSpanMake(0.906448, 0.878906);
self.mapView.region = MKCoordinateRegionMake(centerCoordinate, span);
}

- (void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];


// ---- Start searching ----

[SVProgressHUD showWithStatus:@"Searching..."
maskType:SVProgressHUDMaskTypeGradient];

// San Francisco Caltrain Station
CLLocationCoordinate2D fromCoordinate = CLLocationCoordinate2DMake(37.7764393,
-122.39432299999999);\
// Mountain View Caltrain Station
CLLocationCoordinate2D toCoordinate = CLLocationCoordinate2DMake(37.393879,
-122.076327);

MKPlacemark *fromPlacemark = [[MKPlacemark alloc] initWithCoordinate:fromCoordinate
addressDictionary:nil];

MKPlacemark *toPlacemark = [[MKPlacemark alloc] initWithCoordinate:toCoordinate
addressDictionary:nil];

MKMapItem *fromItem = [[MKMapItem alloc] initWithPlacemark:fromPlacemark];

MKMapItem *toItem = [[MKMapItem alloc] initWithPlacemark:toPlacemark];

[self findDirectionsFrom:fromItem
to:toItem];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


// =============================================================================
#pragma mark - Private

- (void)findDirectionsFrom:(MKMapItem *)source
to:(MKMapItem *)destination
{
MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
request.source = source;
request.destination = destination;
request.requestsAlternateRoutes = YES;

MKDirections *directions = [[MKDirections alloc] initWithRequest:request];

[directions calculateDirectionsWithCompletionHandler:
^(MKDirectionsResponse *response, NSError *error) {

[SVProgressHUD dismiss];

if (error) {

NSLog(@"error:%@", error);
}
else {

MKRoute *route = response.routes[0];

[self.mapView addOverlay:route.polyline];
}
}];
}


// =============================================================================
#pragma mark - MKMapViewDelegate

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView
rendererForOverlay:(id<MKOverlay>)overlay
{
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithOverlay:overlay];
renderer.lineWidth = 5.0;
renderer.strokeColor = [UIColor purpleColor];
return renderer;
}

@end
31 changes: 31 additions & 0 deletions iOS7Sampler/SampleViewControllers/MapDirectionsViewController.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3742"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MapDirectionsViewController">
<connections>
<outlet property="mapView" destination="04G-YU-1Pj" id="Pqa-KT-T1C"/>
<outlet property="view" destination="1" id="3"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="1">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" mapType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="04G-YU-1Pj">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<connections>
<outlet property="delegate" destination="-1" id="F4W-Np-nIF"/>
</connections>
</mapView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
</view>
</objects>
</document>
13 changes: 13 additions & 0 deletions iOS7Sampler/SampleViewControllers/MapOverlaysViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// MapOverlaysViewController.h
// iOS7Sampler
//
// Created by shuichi on 9/24/13.
// Copyright (c) 2013 Shuichi Tsutsumi. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MapOverlaysViewController : UIViewController

@end
40 changes: 40 additions & 0 deletions iOS7Sampler/SampleViewControllers/MapOverlaysViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// MapOverlaysViewController.m
// iOS7Sampler
//
// Created by shuichi on 9/24/13.
// Copyright (c) 2013 Shuichi Tsutsumi. All rights reserved.
//

#import "MapOverlaysViewController.h"
#import <MapKit/MapKit.h>


@interface MapOverlaysViewController ()
@property (nonatomic, weak) IBOutlet MKMapView *mapView;
@end


@implementation MapOverlaysViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
28 changes: 28 additions & 0 deletions iOS7Sampler/SampleViewControllers/MapOverlaysViewController.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3742"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MapOverlaysViewController">
<connections>
<outlet property="mapView" destination="AyI-VV-538" id="fdf-kf-vzH"/>
<outlet property="view" destination="1" id="3"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="1">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" mapType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="AyI-VV-538">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</mapView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
</view>
</objects>
</document>

0 comments on commit b1611c4

Please sign in to comment.