iPhone - Get City name from Latitude and Longtiude

前端 未结 10 944
难免孤独
难免孤独 2020-12-05 06:04

I want get my Current City name in my iPhone App.

I\'m currently getting the latitude and longitude using CLLocationManager and than i am passing my coordinates into

10条回答
  •  一个人的身影
    2020-12-05 06:11

    Please check the bellow function

    func getDataCity(tmpLat:Double,tmpLong:Double) {
    
        let tmpCLGeocoder = CLGeocoder.init()
        if tmpLat > 0 , tmpLong > 0
        {
            let tmpDataLoc = CLLocation.init(latitude: tmpLat, longitude: tmpLong)
    
            tmpCLGeocoder.reverseGeocodeLocation(tmpDataLoc, completionHandler: {(placemarks,error) in
    
                guard let tmpPlacemarks = placemarks else{
                    return
                }
                let placeMark = tmpPlacemarks[0] as CLPlacemark
    
                guard let strLocality = placeMark.locality else{
                    return
                }
                // strLocality is your city
                guard let strSubLocality = placeMark.subLocality else{
    
                    return
                }
                // strSubLocality is your are of city
            })
        }
    }
    

提交回复
热议问题