Skip to content

Commit c25786a

Browse files
author
dskwf
authored
Merge pull request #2 from MarioMatheus/development
Configure interface with MapView
2 parents 3e0d9de + 25c9485 commit c25786a

File tree

4 files changed

+102
-4
lines changed

4 files changed

+102
-4
lines changed

MapKit-Example.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
F2D44C70216F751300B2953C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F2D44C6E216F751300B2953C /* Main.storyboard */; };
1313
F2D44C72216F751400B2953C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F2D44C71216F751400B2953C /* Assets.xcassets */; };
1414
F2D44C75216F751400B2953C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F2D44C73216F751400B2953C /* LaunchScreen.storyboard */; };
15+
F2D44C7E216F7F0000B2953C /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F2D44C7D216F7F0000B2953C /* CoreLocation.framework */; };
1516
/* End PBXBuildFile section */
1617

1718
/* Begin PBXFileReference section */
@@ -22,13 +23,15 @@
2223
F2D44C71216F751400B2953C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2324
F2D44C74216F751400B2953C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2425
F2D44C76216F751400B2953C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
26+
F2D44C7D216F7F0000B2953C /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
2527
/* End PBXFileReference section */
2628

2729
/* Begin PBXFrameworksBuildPhase section */
2830
F2D44C64216F751300B2953C /* Frameworks */ = {
2931
isa = PBXFrameworksBuildPhase;
3032
buildActionMask = 2147483647;
3133
files = (
34+
F2D44C7E216F7F0000B2953C /* CoreLocation.framework in Frameworks */,
3235
);
3336
runOnlyForDeploymentPostprocessing = 0;
3437
};
@@ -40,6 +43,7 @@
4043
children = (
4144
F2D44C69216F751300B2953C /* MapKit-Example */,
4245
F2D44C68216F751300B2953C /* Products */,
46+
F2D44C7C216F7F0000B2953C /* Frameworks */,
4347
);
4448
sourceTree = "<group>";
4549
};
@@ -64,6 +68,14 @@
6468
path = "MapKit-Example";
6569
sourceTree = "<group>";
6670
};
71+
F2D44C7C216F7F0000B2953C /* Frameworks */ = {
72+
isa = PBXGroup;
73+
children = (
74+
F2D44C7D216F7F0000B2953C /* CoreLocation.framework */,
75+
);
76+
name = Frameworks;
77+
sourceTree = "<group>";
78+
};
6779
/* End PBXGroup section */
6880

6981
/* Begin PBXNativeTarget section */
+44-3
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,65 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="m4p-WB-57m">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
7+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
58
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
69
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
710
</dependencies>
811
<scenes>
912
<!--View Controller-->
1013
<scene sceneID="tne-QT-ifu">
1114
<objects>
12-
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
15+
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="MapKit_Example" customModuleProvider="target" sceneMemberID="viewController">
1316
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
1417
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1518
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<subviews>
20+
<mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" mapType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="cO7-Aj-zmM">
21+
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
22+
</mapView>
23+
</subviews>
1624
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
25+
<constraints>
26+
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="cO7-Aj-zmM" secondAttribute="bottom" id="8Jm-lE-UQY"/>
27+
<constraint firstItem="cO7-Aj-zmM" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="KQ3-cL-w4y"/>
28+
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="cO7-Aj-zmM" secondAttribute="trailing" id="NyB-jg-2ii"/>
29+
<constraint firstItem="cO7-Aj-zmM" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="h0H-0w-cxx"/>
30+
</constraints>
1731
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
1832
</view>
33+
<navigationItem key="navigationItem" id="UoQ-g9-cNp"/>
34+
<connections>
35+
<outlet property="mapView" destination="cO7-Aj-zmM" id="mCx-t1-Zdt"/>
36+
</connections>
1937
</viewController>
2038
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
2139
</objects>
40+
<point key="canvasLocation" x="1076" y="133.5832083958021"/>
41+
</scene>
42+
<!--Navigation Controller-->
43+
<scene sceneID="dxG-0r-7VY">
44+
<objects>
45+
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="m4p-WB-57m" sceneMemberID="viewController">
46+
<toolbarItems/>
47+
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="DBZ-vV-saf">
48+
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
49+
<autoresizingMask key="autoresizingMask"/>
50+
<color key="barTintColor" red="1" green="0.57637232540000005" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
51+
<textAttributes key="titleTextAttributes">
52+
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
53+
</textAttributes>
54+
</navigationBar>
55+
<nil name="viewControllers"/>
56+
<connections>
57+
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="5QE-nU-lt2"/>
58+
</connections>
59+
</navigationController>
60+
<placeholder placeholderIdentifier="IBFirstResponder" id="Oaf-ES-svV" userLabel="First Responder" sceneMemberID="firstResponder"/>
61+
</objects>
62+
<point key="canvasLocation" x="226" y="134"/>
2263
</scene>
2364
</scenes>
2465
</document>

MapKit-Example/Info.plist

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>NSLocationWhenInUseUsageDescription</key>
6+
<string>We need your permission to use location services</string>
7+
<key>UIViewControllerBasedStatusBarAppearance</key>
8+
<false/>
59
<key>CFBundleDevelopmentRegion</key>
610
<string>$(DEVELOPMENT_LANGUAGE)</string>
711
<key>CFBundleExecutable</key>
@@ -26,6 +30,8 @@
2630
<string>Main</string>
2731
<key>UIRequiredDeviceCapabilities</key>
2832
<array>
33+
<string>gps</string>
34+
<string>location-services</string>
2935
<string>armv7</string>
3036
</array>
3137
<key>UISupportedInterfaceOrientations</key>

MapKit-Example/ViewController.swift

+40-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,53 @@
77
//
88

99
import UIKit
10+
import MapKit
1011

1112
class ViewController: UIViewController {
1213

14+
@IBOutlet weak var mapView: MKMapView!
15+
16+
let locationManager = CLLocationManager()
17+
var firstOpen = true
18+
1319
override func viewDidLoad() {
1420
super.viewDidLoad()
15-
// Do any additional setup after loading the view, typically from a nib.
21+
title = "MapKit"
22+
mapView.showsUserLocation = true
23+
locationManager.delegate = self
24+
25+
prepareLocationUpdating()
1626
}
27+
28+
29+
func prepareLocationUpdating() {
30+
locationManager.desiredAccuracy = kCLLocationAccuracyBest
31+
locationManager.requestWhenInUseAuthorization()
32+
locationManager.startUpdatingLocation()
33+
}
34+
35+
36+
func showRegionWith(coordinate: CLLocationCoordinate2D) {
37+
let region = MKCoordinateRegion(
38+
center: coordinate,
39+
span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005)
40+
)
41+
42+
mapView.setRegion(region, animated: true)
43+
}
44+
45+
46+
}
1747

1848

49+
extension ViewController: CLLocationManagerDelegate {
50+
51+
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
52+
if firstOpen {
53+
firstOpen = false
54+
showRegionWith(coordinate: locations.last!.coordinate)
55+
}
56+
}
57+
1958
}
2059

0 commit comments

Comments
 (0)