Skip to content

Commit 2e4e269

Browse files
Sachin KesirajuSachin Kesiraju
authored andcommitted
Added Map view.
1 parent 724f08f commit 2e4e269

File tree

4 files changed

+133
-4
lines changed

4 files changed

+133
-4
lines changed

SwiftExample.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
031A8D8A193DB57D00F4A6D2 /* SwiftExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031A8D89193DB57D00F4A6D2 /* SwiftExampleTests.swift */; };
1515
031A8D94193DCBE900F4A6D2 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031A8D93193DCBE900F4A6D2 /* TableViewController.swift */; };
1616
031A8D9A193DDD4100F4A6D2 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031A8D99193DDD4100F4A6D2 /* WebViewController.swift */; };
17+
03345B6A19755286002C0FF7 /* MapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03345B6919755286002C0FF7 /* MapViewController.swift */; };
18+
03345B6C197552AF002C0FF7 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03345B6B197552AF002C0FF7 /* MapKit.framework */; };
1719
03B0EEB119595EF00048D16D /* CameraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B0EEB019595EF00048D16D /* CameraViewController.swift */; };
1820
03C94697195AC0C70055D2FC /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03C94696195AC0C70055D2FC /* MobileCoreServices.framework */; };
1921
/* End PBXBuildFile section */
@@ -40,6 +42,8 @@
4042
031A8D89193DB57D00F4A6D2 /* SwiftExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftExampleTests.swift; sourceTree = "<group>"; };
4143
031A8D93193DCBE900F4A6D2 /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
4244
031A8D99193DDD4100F4A6D2 /* WebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = "<group>"; };
45+
03345B6919755286002C0FF7 /* MapViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapViewController.swift; sourceTree = "<group>"; };
46+
03345B6B197552AF002C0FF7 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
4347
03B0EEB019595EF00048D16D /* CameraViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraViewController.swift; sourceTree = "<group>"; };
4448
03C94696195AC0C70055D2FC /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
4549
/* End PBXFileReference section */
@@ -49,6 +53,7 @@
4953
isa = PBXFrameworksBuildPhase;
5054
buildActionMask = 2147483647;
5155
files = (
56+
03345B6C197552AF002C0FF7 /* MapKit.framework in Frameworks */,
5257
03C94697195AC0C70055D2FC /* MobileCoreServices.framework in Frameworks */,
5358
);
5459
runOnlyForDeploymentPostprocessing = 0;
@@ -66,6 +71,7 @@
6671
031A8D68193DB57D00F4A6D2 = {
6772
isa = PBXGroup;
6873
children = (
74+
03345B6B197552AF002C0FF7 /* MapKit.framework */,
6975
03C94696195AC0C70055D2FC /* MobileCoreServices.framework */,
7076
031A8D73193DB57D00F4A6D2 /* SwiftExample */,
7177
031A8D86193DB57D00F4A6D2 /* SwiftExampleTests */,
@@ -87,6 +93,7 @@
8793
children = (
8894
031A8D76193DB57D00F4A6D2 /* AppDelegate.swift */,
8995
031A8D78193DB57D00F4A6D2 /* ViewController.swift */,
96+
03345B6919755286002C0FF7 /* MapViewController.swift */,
9097
031A8D7A193DB57D00F4A6D2 /* Main.storyboard */,
9198
03B0EEB019595EF00048D16D /* CameraViewController.swift */,
9299
031A8D99193DDD4100F4A6D2 /* WebViewController.swift */,
@@ -222,6 +229,7 @@
222229
buildActionMask = 2147483647;
223230
files = (
224231
031A8D79193DB57D00F4A6D2 /* ViewController.swift in Sources */,
232+
03345B6A19755286002C0FF7 /* MapViewController.swift in Sources */,
225233
031A8D94193DCBE900F4A6D2 /* TableViewController.swift in Sources */,
226234
031A8D77193DB57D00F4A6D2 /* AppDelegate.swift in Sources */,
227235
031A8D9A193DDD4100F4A6D2 /* WebViewController.swift in Sources */,

SwiftExample/Base.lproj/Main.storyboard

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
2626
</state>
2727
<connections>
28-
<action selector="cameraShow" destination="hKc-Zw-bWd" eventType="touchUpInside" id="Vd6-is-arg"/>
28+
<action selector="cameraShow" destination="hKc-Zw-bWd" eventType="touchUpInside" id="iht-ZB-bX4"/>
2929
</connections>
3030
</button>
3131
</subviews>
3232
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
3333
</view>
3434
<navigationItem key="navigationItem" title="Camera" id="HBa-xH-yGn"/>
3535
<connections>
36-
<outlet property="backgroundImage" destination="XQE-kM-aDn" id="hD5-mh-LmV"/>
36+
<outlet property="backgroundImage" destination="XQE-kM-aDn" id="lXX-tv-siF"/>
3737
</connections>
3838
</viewController>
3939
<placeholder placeholderIdentifier="IBFirstResponder" id="uwF-Py-j21" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -79,6 +79,15 @@
7979
<segue destination="hKc-Zw-bWd" kind="push" id="ahm-DB-Vle"/>
8080
</connections>
8181
</button>
82+
<button appearanceType="aqua" opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OWE-sn-Ss1">
83+
<rect key="frame" x="126" y="373" width="68" height="30"/>
84+
<state key="normal" title="View Map">
85+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
86+
</state>
87+
<connections>
88+
<segue destination="7RA-yL-fnV" kind="push" id="UVz-K3-vd8"/>
89+
</connections>
90+
</button>
8291
</subviews>
8392
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
8493
</view>
@@ -91,7 +100,7 @@
91100
<!--Web View Controller-->
92101
<scene sceneID="VOw-Q8-ULY">
93102
<objects>
94-
<viewController id="wf8-3g-qWu" customClass="WebViewController" customModule="SwiftExample" customModuleProvider="target" sceneMemberID="viewController">
103+
<viewController id="wf8-3g-qWu" customClass="WebViewController" sceneMemberID="viewController">
95104
<layoutGuides>
96105
<viewControllerLayoutGuide type="top" id="3O0-E3-k1G"/>
97106
<viewControllerLayoutGuide type="bottom" id="NIx-Kj-uFu"/>
@@ -116,10 +125,37 @@
116125
</objects>
117126
<point key="canvasLocation" x="1044" y="835"/>
118127
</scene>
128+
<!--Map View Controller - Map-->
129+
<scene sceneID="uUf-GJ-RqD">
130+
<objects>
131+
<viewController id="7RA-yL-fnV" customClass="MapViewController" customModule="SwiftExample" customModuleProvider="target" sceneMemberID="viewController">
132+
<layoutGuides>
133+
<viewControllerLayoutGuide type="top" id="bR2-Mi-XwT"/>
134+
<viewControllerLayoutGuide type="bottom" id="xwN-Sp-Mnf"/>
135+
</layoutGuides>
136+
<view key="view" contentMode="scaleToFill" id="fB1-h8-Ijs">
137+
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
138+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
139+
<subviews>
140+
<mapView appearanceType="aqua" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" mapType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="Ja9-rN-D64">
141+
<rect key="frame" x="0.0" y="64" width="320" height="416"/>
142+
</mapView>
143+
</subviews>
144+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
145+
</view>
146+
<navigationItem key="navigationItem" title="Map" id="ahj-KB-B5f"/>
147+
<connections>
148+
<outlet property="mapView" destination="Ja9-rN-D64" id="0Tk-t9-jZb"/>
149+
</connections>
150+
</viewController>
151+
<placeholder placeholderIdentifier="IBFirstResponder" id="ay5-IV-05t" userLabel="First Responder" sceneMemberID="firstResponder"/>
152+
</objects>
153+
<point key="canvasLocation" x="1504" y="892"/>
154+
</scene>
119155
<!--Table View Controller-->
120156
<scene sceneID="NnP-1b-wea">
121157
<objects>
122-
<tableViewController id="b2E-rT-I2x" customClass="TableViewController" customModule="SwiftExample" customModuleProvider="target" sceneMemberID="viewController">
158+
<tableViewController id="b2E-rT-I2x" customClass="TableViewController" sceneMemberID="viewController">
123159
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="sBK-2t-OEb">
124160
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
125161
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -139,6 +175,9 @@
139175
<outlet property="delegate" destination="b2E-rT-I2x" id="bSw-U0-Jsh"/>
140176
</connections>
141177
</tableView>
178+
<toolbarItems/>
179+
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
180+
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
142181
</tableViewController>
143182
<placeholder placeholderIdentifier="IBFirstResponder" id="XpV-KF-eus" userLabel="First Responder" sceneMemberID="firstResponder"/>
144183
</objects>

SwiftExample/MapViewController.swift

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//
2+
// MapViewController.swift
3+
// SwiftExample
4+
//
5+
// Created by Sachin Kesiraju on 7/15/14.
6+
// Copyright (c) 2014 Sachin Kesiraju. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import MapKit
11+
import CoreLocation
12+
13+
class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
14+
15+
@IBOutlet var mapView : MKMapView
16+
17+
init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
18+
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
19+
// Custom initialization
20+
}
21+
22+
init(coder aDecoder: NSCoder!) {
23+
super.init(coder: aDecoder)
24+
}
25+
26+
override func viewDidLoad() {
27+
super.viewDidLoad()
28+
// Do any additional setup after loading the view.
29+
30+
self.mapView.delegate = self
31+
let location = "1 Infinity Loop, Cupertino, CA"
32+
var geocoder:CLGeocoder = CLGeocoder()
33+
geocoder.geocodeAddressString(location, {(placemarks: AnyObject[]!, error: NSError!) -> Void in
34+
35+
if(error){
36+
37+
println("Error", error)
38+
}
39+
40+
else if let placemark = placemarks?[0] as? CLPlacemark {
41+
42+
var placemark:CLPlacemark = placemarks[0] as CLPlacemark
43+
var coordinates:CLLocationCoordinate2D = placemark.location.coordinate
44+
45+
var pointAnnotation:MKPointAnnotation = MKPointAnnotation()
46+
pointAnnotation.coordinate = coordinates
47+
pointAnnotation.title = "Apple HQ"
48+
49+
self.mapView.addAnnotation(pointAnnotation)
50+
self.mapView.centerCoordinate = coordinates
51+
self.mapView.selectAnnotation(pointAnnotation, animated: true)
52+
53+
println("Added annotation to map view")
54+
}
55+
56+
})
57+
}
58+
59+
func mapView (mapView: MKMapView!,
60+
viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
61+
62+
var pinView:MKPinAnnotationView = MKPinAnnotationView()
63+
pinView.annotation = annotation
64+
pinView.pinColor = MKPinAnnotationColor.Red
65+
pinView.animatesDrop = true
66+
pinView.canShowCallout = true
67+
68+
return pinView
69+
}
70+
71+
func mapView(mapView: MKMapView!,
72+
didSelectAnnotationView view: MKAnnotationView!){
73+
74+
println("Selected annotation")
75+
}
76+
77+
override func didReceiveMemoryWarning() {
78+
super.didReceiveMemoryWarning()
79+
// Dispose of any resources that can be recreated.
80+
}
81+
82+
}

0 commit comments

Comments
 (0)