gpt4 book ai didi

ios - Swift,靠近用户位置

转载 作者:行者123 更新时间:2023-11-28 15:18:38 25 4
gpt4 key购买 nike

我是开发新手,我正在按照我使用此代码的教程在我的应用程序 View 中添加谷歌地图

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location: CLLocation = locations.last!
print("Location: \(location)")

let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude,
longitude: location.coordinate.longitude,
zoom: zoomlevel)


let marker = GMSMarker()
marker.title = "My Position"

marker.map = mapView
if mapView.isHidden {
mapView.isHidden = false
mapView.camera = camera
} else {
mapView.animate(to: camera)
}


}


func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .restricted:
print("Location access was restricted.")
case .denied:
print("User denied access to location.")

mapView.isHidden = false
case .notDetermined:
print("Location status not determined.")
case .authorizedAlways: fallthrough
case .authorizedWhenInUse:
print("Location status is OK.")
}
}


func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
locationManager.stopUpdatingLocation()
print("Error: \(error)")
}

要查找用户位置,现在我想在 map 上查看距用户位置 X 距离的地点(谷歌地点),我该怎么做?我在 google places doc 上搜索但没有找到有效答案

最佳答案

在 mapView 上添加另一个标记 onTap 并使其可拖动,并使用 CLLocationDistance 测量两个位置之间的距离。

let distanceInMeters = self.locationManager.location?.distance(from: newMarkerLocation!)

关于ios - Swift,靠近用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46402544/

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