forked from shu223/iOS7-Sampler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
iOS7Sampler/SampleViewControllers/MapDirectionsViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
122
iOS7Sampler/SampleViewControllers/MapDirectionsViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
iOS7Sampler/SampleViewControllers/MapDirectionsViewController.xib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
iOS7Sampler/SampleViewControllers/MapOverlaysViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
iOS7Sampler/SampleViewControllers/MapOverlaysViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
iOS7Sampler/SampleViewControllers/MapOverlaysViewController.xib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |