我知道可以显示当前位置并将其居中放置在“地图工具包视图”中。但是有可能使它偏移到Map Kit视图的顶部或底部吗?
我知道以下位置当前位置很好且居中,但是如何显示偏移量呢?
let viewRegion = MKCoordinateRegion(center: userLocation, latitudinalMeters: 200, longitudinalMeters: 200)
mapView.setRegion(viewRegion, animated: false)
答案 0 :(得分:-1)
利用相机使用坐标将位置居中
对于MKMapView
let userCoordinate = CLLocationCoordinate2D(latitude: <lat>, longitude: <long>)
let eyeCoordinate = CLLocationCoordinate2D(latitude: <lat>, longitude: <long>)
let mapCamera = MKMapCamera(lookingAtCenter: userCoordinate, fromEyeCoordinate: eyeCoordinate, eyeAltitude:400.0)
let annotation = MKPointAnnotation()
annotation.setCoordinate(userCoordinate)
对于Google Maps
let camera = GMSCameraPosition.camera(withLatitude: myLatitude, longitude: myLongitude, zoom: zoomLevel)
mapView = GMSMapView.map(withFrame: view.bounds, camera: camera)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.camera = GMSCameraPosition.camera(withTarget: CLLocationCoordinate2D(latitude: <userLocationLatitude>, longitude: <userLocationLongitude>, zoom: 12.0)