Swift Map Usage

The map now becomes necessary to use map, location in every application. I explained how to do these things for Xamarin. In this article I will explain how to do this with Swift. In order to use Google Maps with Xamarin, we needed to get an API Key from Google. We had to load the plugins. For Swift, we will handle them very easily without any need.

First of all, in our project, we have a .storyboard extension file and we add our Map Kit View object. We will show our map on this object. Let’s leave some space in the top and put a button here. This button will help us find our position. We create an outlet for our Map Kit View object. For the button, we create an action. This part of our design looks like this.

After we have finished the design part and created our outlet and actions, we can start writing our codes. First we need to add 2 frameworks. If we do not add these frameworks, the map object we added in the design section will also fail. There are 2 methods to add Framework. From these, we come to the top of the project – the map file at the top left – the file. My screen comes up like this.

Here we can go to Capabilities and activate the Maps option. This is the simplest way, the other way is to add the individual framework. On the same screen again we come to the option of Build Phases. Under this option we will add 2 items into Link Binary With Libraries. MapKit.framework is a framework that will be added to your map object so that it will not fail and work properly. We added CoreLocation.framework to find our location.

Now we’re in code. First we bind class with CLLocationManagerDelegate. Then we create a map manager and start writing our codes. Each line of code is described with the description lines above the codes. In addition, the map is displayed in 3 different formats. These;

  1. Normal View
  2. Satellite View
  3. Hybrid View

If you have any questions that you have in mind, you can reach us by comment or mail.

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.