在我的项目中,我正在使用Google Map。我启用这样的当前位置点:
self.mapView?.isMyLocationEnabled = true
之后,我将得到当前位置的纬度和经度,如下所示:
guard let currentLat = self.mapView?.myLocation?.coordinate.latitude,
let currentLan = self.mapView?.myLocation?.coordinate.longitude else {
showMessageFail(title: "Fail", myMessage: "Could not determine your current location")
return
}
然后像这样将相机聚焦在当前位置:
let currentPosition = CLLocationCoordinate2D(latitude: currentLat, longitude: currentLan)
self.mapView?.animate(toLocation: self.currentPosition)
一切都很好,现在它在地图中心显示了当前位置点(谷歌地图上的蓝色点)。现在,当当前位置发生变化时,假设我在车上,当前位置点就会移动,在某个点上它会移动到地图范围之外。如何始终将当前位置点保留在地图中心,而不移动地图点。任何帮助将非常感激。
最佳答案
currLocation = manager.location!
let locationOfDevice: CLLocation = currLocation // this determines the location of the device using the users location
let deviceCoordinate: CLLocationCoordinate2D = locationOfDevice.coordinate // determines the coordinates of the device using the location device variabel which has in it the user location.
let span = MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1) // this determines the span in which its determined that 1 degree is 69 miles.
let region = MKCoordinateRegion(center: deviceCoordinate, span: span) // set the center equal to the device coordinates and the span equal to the span variable we have created this will give you the region.
mapView.setRegion(region, animated: true);
关于swift - 如何在移动,谷歌 map ,快速移动时将当前位置点保持在 map 中心,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48494757/