我是一名初学者,正在开发我在我的应用程序视图中添加谷歌地图,遵循我使用此代码的教程
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)")
}
找到用户位置,现在我想在地图上看到距用户位置X距离的地方(谷歌地点),我该怎么办?我搜索了谷歌的地方文档但没有找到有效的答案
答案 0 :(得分:1)
在mapView上添加另一个标记onTap并使其可拖动,并使用CLLocationDistance测量2个位置之间的距离。
let distanceInMeters = self.locationManager.location?.distance(from: newMarkerLocation!)