我需要将 NMAMapView 缩放到 map 边界内的特定点。假设我们有一些标记作为该 map 的 subview ,其位置为 pinPoint: CGPoint
。
我尝试使用 NMAMapView 的 transformCenter
属性,如下所示:
let transformCenter = CGPoint(x: pinPoint.x / mapView.bounds.width, y: pinPoint.y / mapView.bounds.height) // x and y are in range [0, 1]
mapView.transformCenter = transformCenter
mapView.set(zoomLevel: mapView.zoomLevel + 1, animation: .linear)
但是此代码将 map 缩放到其框架中心,而不是 pinPoint。
我还尝试使用以下代码将 map 缩放到所需的点:
guard let coordinates = mapView.geoCoordinates(from: pinPoint) else {
return
}
mapView.set(coordinates: coordinates, to: pinPoint, animation: .linear, zoomLevel: mapView.zoomLevel + 1)
但这也无法正常工作:缩放后,标记下方的地理坐标在每个缩放步骤后都会更改。
最佳答案
请尝试使用此代码,此代码仅供您引用,您需要根据您的要求进行修改。
// create geo coordinate
let geoCoordCenter = NMAGeoCoordinates(latitude: 49.260327, longitude: -123.115025)
// set map view with geo center
self.mapView.set(geoCenter: geoCoordCenter, animation:NMAMapAnimation.none)
// set zoom level
self.mapView.zoomLevel = 13.2
请查看更多示例GitHub .
关于ios - HEREMaps iOS : Zoom to specific point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54580374/