{"id":1171,"date":"2018-04-25T12:30:45","date_gmt":"2018-04-25T12:30:45","guid":{"rendered":"http:\/\/sezeromer.com\/?p=1171"},"modified":"2023-02-26T14:03:35","modified_gmt":"2023-02-26T11:03:35","slug":"swift-harita-kullanimi","status":"publish","type":"post","link":"https:\/\/sezeromer.com\/en\/swift-harita-kullanimi\/","title":{"rendered":"Swift Map Usage"},"content":{"rendered":"<p>The map now becomes necessary to use map, location in every application. I explained how to do these things for <strong>Xamarin<\/strong>. In this article I will explain how to do this with <strong>Swift<\/strong>. In order to use Google Maps with Xamarin, we needed to get an <strong>API<\/strong> <strong>Key<\/strong> from <strong>Google<\/strong>. We had to load the plugins. For <strong>Swift<\/strong>, we will handle them very easily without any need.<\/p>\n<p>First of all, in our project, we have a .storyboard extension file and we add our <strong>Map<\/strong> <strong>Kit<\/strong> <strong>View<\/strong> object. We will show our map on this object. Let&#8217;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 <strong>Map Kit View<\/strong> object. For the button, we create an action. This part of our design looks like this.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1177\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-1.png\" sizes=\"(max-width: 1440px) 100vw, 1440px\" srcset=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-1.png 1440w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-1-300x188.png 300w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-1-768x480.png 768w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-1-1024x640.png 1024w\" alt=\"\" width=\"1440\" height=\"900\" \/><\/p>\n<p>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 &#8211; the map file at the top left &#8211; the file. My screen comes up like this.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1178\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-2.png\" sizes=\"(max-width: 1440px) 100vw, 1440px\" srcset=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-2.png 1440w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-2-300x188.png 300w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-2-768x480.png 768w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-2-1024x640.png 1024w\" alt=\"\" width=\"1440\" height=\"900\" \/><\/p>\n<p>Here we can go to Capabilities and activate the <strong>Maps<\/strong> 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. <strong>MapKit.framework<\/strong> is a framework that will be added to your map object so that it will not fail and work properly. We added <strong>CoreLocation.framework<\/strong> to find our location.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1179\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-3.png\" sizes=\"(max-width: 1440px) 100vw, 1440px\" srcset=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-3.png 1440w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-3-300x188.png 300w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-3-768x480.png 768w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/04\/harita-3-1024x640.png 1024w\" alt=\"\" width=\"1440\" height=\"900\" \/><\/p>\n<p>Now we&#8217;re in code. First we bind class with <strong>CLLocationManagerDelegate<\/strong>. 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;<\/p>\n<ol>\n<li>Normal View<\/li>\n<li>Satellite View<\/li>\n<li>Hybrid View<\/li>\n<\/ol>\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">harita.mapType=MKMapType.hybrid<\/pre>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">class ViewController: UIViewController,CLLocationManagerDelegate {\r\n    @IBOutlet weak var harita: MKMapView!\r\n    var haritaYoneticisi = CLLocationManager()\r\n    override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n        \/\/ Do any additional setup after loading the view, typically from a nib.\r\n    }\r\n    @IBAction func YerimiBul(_ sender: Any) {\r\n        \r\n        haritaYoneticisi.delegate=self\r\n        \r\n        \/\/ \u0130stenilen do\u011fruluk oran\u0131n\u0131 belirliyoruz\r\n        haritaYoneticisi.desiredAccuracy = kCLLocationAccuracyBest\r\n        \r\n        \/\/ Bu sayfay\u0131 a\u00e7t\u0131\u011f\u0131nda kullan\u0131c\u0131 bu kod par\u00e7as\u0131 konum kullanaca\u011f\u0131n\u0131 kullan\u0131c\u0131ya bildiriyor\r\n        haritaYoneticisi.requestWhenInUseAuthorization()\r\n        haritaYoneticisi.startUpdatingLocation()\r\n        harita.showsUserLocation = true\r\n        \r\n    }<\/pre>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\"> \/\/Bu fonksyion ile konum bulumu bittikten sonra olacaklar\u0131 yaz\u0131yrum\r\n    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {\r\n        \/\/ ilk olarak kullaniciAlani ad\u0131nda bir de\u011fi\u015fen olu\u015fturdu ard\u0131ndan bunun CLLocations tipinde oldu\u011funu bildirdik.\r\n        \/\/Gelen locations de\u011ferleri aras\u0131ndan ilkini se\u00e7iyoruz ve bunun kullaniciAlani de\u011fi\u015fkenine at\u0131yrouz\r\n        let kullaniciAlani:CLLocation = locations[0] as CLLocation\r\n        \r\n        \/\/Gerekli olan de\u011feri ald\u0131ktan sonra harita yoneticisinin kendini g\u00fcncellemesini durduruypruz.\r\n        haritaYoneticisi.stopUpdatingLocation()\r\n        \r\n        \r\n        \/\/ Sonras\u0131nda alan de\u011fi\u015fkeni olu\u015fturup buna bir 2 boyutlu harita olmas\u0131n\u0131 istiyoruz ard\u0131nda koordinatlar\u0131 ise ald\u0131\u011f\u0131m\u0131za veriyoruz\r\n        let Alan = CLLocationCoordinate2D(latitude: kullaniciAlani.coordinate.latitude, longitude: kullaniciAlani.coordinate.longitude)\r\n        \r\n        \/\/ B\u00f6lgenin ne kadar uzaktan a\u00e7\u0131lmas\u0131n\u0131 istiyorsak bunu belirtiyouz.\r\n        let aralik = MKCoordinateSpanMake(0.8, 0.8)\r\n        \r\n        let bolge = MKCoordinateRegion(center: Alan, span: aralik)\r\n        harita.setRegion(bolge, animated: true)\r\n        \r\n    }\r\n}<\/pre>\n<\/div>\n<\/div>\n<p>If you have any questions that you have in mind, you can reach us by comment or mail.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1209,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[327],"tags":[421,425,423,98,172,171,422,424,420,328,22],"class_list":["post-1171","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swift","tag-apple","tag-corelocation-framework","tag-framework","tag-google","tag-harita","tag-map","tag-map-kit-view","tag-mapkit-framework","tag-maps","tag-swift","tag-xamarin"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1171"}],"collection":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/comments?post=1171"}],"version-history":[{"count":4,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1171\/revisions"}],"predecessor-version":[{"id":2589,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1171\/revisions\/2589"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media\/1209"}],"wp:attachment":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media?parent=1171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/categories?post=1171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/tags?post=1171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}