0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

緯度経度から住所などに変換

Posted at

今回の内容

  • 緯度経度から住所などに変換

コードと簡単解説

  • func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {}内でlocationsから緯度と経度を取得します。
  • 取得してきた緯度と経度からreverseGeocodeLocationにより住所などに変換して利用することができる。
    //使用者の現在地の緯度と経度を取得して、住所か建物の名前などに変換
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        
        CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: (locations.first?.coordinate.latitude)!, longitude: (locations.first?.coordinate.longitude)!)) { placeMark, error in
            
            if error != nil{
                
                return
            }
            
            if let resultPlaceMark = placeMark?.first{
                
                if resultPlaceMark.administrativeArea != nil || resultPlaceMark.locality != nil{
                    
                    self.currentLocationLabel.text = resultPlaceMark.name! + resultPlaceMark.administrativeArea!
                    
                }else{
                    
                    self.currentLocationLabel.text = resultPlaceMark.name!
                }
            }
        }
    }

終わり

ご指摘、ご質問などありましたら、コメントまでお願い致します。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?