斯威夫特,乘坐附近的用户位置的地方
问题描述:
我在制定我加入我的应用程序的视图中的谷歌地图,下面的教程我用这个代码斯威夫特,乘坐附近的用户位置的地方
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距离的地方(谷歌地点),我该如何做?我搜索了谷歌的地方文件,但没有找到有效的答案
答
在mapView上添加另一个标记onTap并使其可拖动并使用CLLocationDistance来测量2个位置之间的距离。
let distanceInMeters = self.locationManager.location?.distance(from: newMarkerLocation!)
这是你在找什么:[https://stackoverflow.com/questions/44333550/get-list-of-nearby-places-from-google-places-api-swift-3]? ? – 2017-09-25 10:12:50