LoginSignup
4
3

More than 3 years have passed since last update.

【Swift】地図で中心地を一度だけ現在地にする方法(指離すと中心に戻るの悲しいのでやめたい)

Last updated at Posted at 2017-10-06

地図を使ったアプリで中心地を最初だけ現在地にする方法

本当に困ったので今後のためにメモ

これをしておかないと他のところを見ようと思って動かしても
手を離すと地図が現在地(もともと定めた中心地)に戻っちゃう
それを防止するためのコード

めちゃめちゃ端折った
現在地って書いてますが中心地は自分で定めたもので大丈夫
現在地でも、自分で決めたLatitudeとLongitude(緯度経度)でも

とりあえずシュンって中心に戻って"うお?!"ってなるのを防ぐためのコード

import MapKit
import CoreLocation

class mapViewController: UIViewController, MKMapViewDelegate,CLLocationManagerDelegate{

//フラグ立て

    var regionout:Bool = false

    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        if regionout == false {
        switch status {
        case .notDetermined:
            self.locationManager.requestWhenInUseAuthorization()
        case .restricted, .denied:
            break
        case .authorizedAlways, .authorizedWhenInUse:
            break

            }
            regionout = true
        }
}

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3