UrbanPro
true

Learn iOS Developer from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

MapKit Tutorial with Swift in iOS 8

Naga Kranthi
24/05/2017 0 0

Using Map Kit, the portion of the map that is displayed on the screen is referred to as the region. The region is defined by a center location and  a span of the surrounding area to be displayed. Inside the Map View an annotation could be created, indication a Point of Interest. In this tutorial we will display  a portion of the city London and we will add an annotation of the Big Ben. This tutorial makes use of Xcode 6 and is build for iOS8.

Open Xcode and create a new Single View Application. For product name, use iOS8 Swift Map Kit Tutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and make sure only iPhone is selected in Devices.

Go to the storyboard. In Xcode 6 view controllers are now square by default, so that you can create one user interface use just for multiple devices. In iOS8 you can layout the storyboard using constraints and size classes. Since this app is only going to be for the iPhone, you can disable size classes. In the File Inspector untick Use Size Classes.

Choose Keep size class data for: iPhone, and click Disable Size Classes.

Drag a MapKit View  to the main View. Give the MapKit View the same size as its parent view. The StoryBoard should look like this.

Select the Assistant Editor and open ViewController.swift. Ctrl and drag from the Segmented Control to the ViewController.swift and create the following Outlet.

 

Change the viewDidLoad method in

override func viewDidLoad() {
super.viewDidLoad()
// 1
let location = CLLocationCoordinate2D(
latitude: 51.50007773,
longitude: -0.1246402
)
// 2
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: location, span: span)
mapView.setRegion(region, animated: true)

//3
let annotation = MKPointAnnotation()
annotation.setCoordinate(location)
annotation.title = “Big Ben”
annotation.subtitle = “London”
mapView.addAnnotation(annotation)
}

  1. The latitude and longitude of the city of London is assigned to location constant using the CLLocationCoordinate2d struct
  2. The span value is made relative small, so a big portion of London is visible. The MKCoordinateRegion method defines the visible region, it is set with the setRegion method.
  3. An annotation is created at the current coordinates with the MKPointAnnotaition class. The annotation is added to the Map View with the addAnnotation method.

Build and Run the project, The city of London, including the annotation will be diplayed.

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Working With Arrays in Swift
Swift Arrays:Like Objective C arrays Swift arrays are also collection of Objects The Difference is in swift we don't work directly with addresses.The declaration of Swift array is as follows The above...

On the Job training is always best
On the job training always provides an opportunity to learn the best industry practices. While you work on real time you would encounter many challenges that will force you to learn many new things. Class...
M

Developing iOS Apps Part 1
The Basics Swift opts to use a Javascript-like ‘var’ keyword to define any new variable. So for example to create a new variable with a bit of text in it, you would have this: var...

P Balasubramanyam

0 0
0

10 Ways My Life Changed When I Learned To Code
1. I have freedom to make my own schedule. 2. I earn more, but work fewer hours. 3. I can say “no” to job offers. 4. People come to me asking if I can work for them. 5. I never have to...

Learning Path For Mobile Application Development
I. Traditional Approach: 1. Native Android Application Development: Android is a mobile operating system that runs on phones, tablets, smartwatches, TVs and more. You can learn Android Application Development...
X

Looking for iOS Developer Classes?

The best tutors for iOS Developer Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn iOS Developer with the Best Tutors

The best Tutors for iOS Developer Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more