gpt4 book ai didi

ios - 用户如何将图钉位置拖到另一个位置,并使 GPS 采用这个新的坐标。 swift

转载 作者:行者123 更新时间:2023-11-30 13:40:18 25 4
gpt4 key购买 nike

我希望用户能够将图钉的位置拖动到另一条街道上,这样应用程序就会采用这些新位置。

代码如下:

最佳答案

// Function to manage the location of the User
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

let location:CLLocationCoordinate2D = manager.location!.coordinate
locationManager.stopUpdatingLocation() // Stop location

print("location = \(location.latitude)\(location.latitude)")

latitude = location.latitude
longitude = location.longitude

let center = CLLocationCoordinate2D (latitude: location.latitude, longitude: location.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpanMake(0.01, 0.01))

self.map.setRegion(region, animated: true)

self.map.removeAnnotations(map.annotations)

let pinLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.latitude, location.longitude)
let pinAnnotation = MKPointAnnotation()
pinAnnotation.coordinate = pinLocation
pinAnnotation.title = "Você"

self.map.addAnnotation(pinAnnotation)


//Funcao para pegar a localizacao e transformar em nome
let requestCLLocation = CLLocation(latitude: self.latitude, longitude: self.longitude)
CLGeocoder().reverseGeocodeLocation(requestCLLocation, completionHandler: {(placemarks, error) -> Void in

if (error != nil){
print(error!)
}else{
if placemarks!.count > 0 {
let p = CLPlacemark(placemark: (placemarks?[0])! as CLPlacemark)



var locationName = p.addressDictionary!["Name"] as? NSString
var bairro = p.addressDictionary!["SubLocality"] as? NSString
var city = p.addressDictionary!["City"] as? NSString
var state = p.addressDictionary!["State"] as? NSString

if (locationName == nil){
locationName = "Rua não encontrada"
}

if (bairro == nil){
bairro = "Bairro não encontrado"
}

if (city == nil){
city = "Cidade não encontrada"
}

if (state == nil){
state = "Erro"
}


//Street name in Label
self.streetName.text = ((locationName!) as String)+", "+((bairro!) as String)+", "+((city!) as String)+"-"+((state!) as String)

}
}})


}

关于ios - 用户如何将图钉位置拖到另一个位置,并使 GPS 采用这个新的坐标。 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35656808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com