当单击地图上的 MKAnnotationViews 时,它们会暂时带到前面。我不希望出现这种行为,因为我有很多 MKAnnotationView,它们只是地图上的图标,没有任何其他功能。
我尝试将 MKAnnotationView 设置userInteractionEnabled为NO但它不起作用。触摸时 MKAnnotationView 仍然会出现在前面。这很令人困惑,因为 MKAnnotationView 只是一个 UIView,所以我无法弄清楚为什么userInteractionEnabled被忽略。
我有一个使用 MapKit 的应用程序。
我在调整地图大小后计算当前缩放。
通过定义(来自MKGeometry.h文件)
MKZoomScale provides a conversion factor between MKMapPoints and screen points.
When MKZoomScale = 1, 1 screen point = 1 MKMapPoint. When MKZoomScale is
0.5, 1 screen point = 2 MKMapPoints.
Run Code Online (Sandbox Code Playgroud)
所以,我是这样计算的:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
CGSize screenSize = mapView.bounds.size;
MKMapRect mapRect = mapView.visibleMapRect;
MKZoomScale zoomScale = screenSize.width * screenSize.height / (mapRect.size.width * mapRect.size.height);
}
Run Code Online (Sandbox Code Playgroud)
计算结果zoomScale符合定义(我已经检查过)。
我还在方法中的 mapView 上绘制了一个叠加层
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
Run Code Online (Sandbox Code Playgroud)
问题是,我的计算结果zoomScale不等于系统传递给该方法的结果。我希望它们相等,因为drawMapRect:在调整大小后立即调用(实际上,调整大小会导致调用此方法)。
这里有什么问题吗?
我也尝试使用
currentZoomScale = …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
MKMapRect mRect = self.mapView.visibleMapRect;
MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMaxY(mRect)/2);
MKMapPoint northMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect)/2, 0);
MKMapPoint southMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect)/2, MKMapRectGetMaxY(mRect));
MKMapPoint westMapPoint = MKMapPointMake(0, MKMapRectGetMaxY(mRect)/2);
Run Code Online (Sandbox Code Playgroud)
我正在将这些转换为CLLocationCoordinate2Dwith MKCoordinateForMapPoint。例如:
CLLocationCoordinate2D northCoords = MKCoordinateForMapPoint(northMapPoint);
Run Code Online (Sandbox Code Playgroud)
与 一起northCoords,我有centerCoordswhich 是地图中心点的坐标。使用这两组坐标,我创建了一个数组,将这两组坐标CLLocationCoordinate2D coordinates[2]添加到其中...
下面,我用下面的代码在两个坐标之间画一条线:
MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:2];
[_mapView addOverlay:polyLine];
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
polylineView.strokeColor = [UIColor redColor];
polylineView.lineWidth = 5.0;
return polylineView;
}
Run Code Online (Sandbox Code Playgroud)
问题:
折线叠加起点(地图中心)始终从中心开始是正确的。然而,线路的另一端(北/南/东/西)没有正确指向它应该在的位置。在下图中,我正在绘制与上面的 4 MKMapPoint …
刚开始使用 Mapbox,通过在 locationManaged didUpdateLocations 中添加它来设法绘制一条 MGLPolyline
var shape = MGLPolyline(coordinates: &a, count: UInt(a.count))
mapView.addAnnotation(shape)
Run Code Online (Sandbox Code Playgroud)
func mapView(mapView: MGLMapView, lineWidthForPolylineAnnotation annotation: MGLPolyline) -> CGFloat { return 20.0 }
我到处搜索,但我找不到它。我想下面的动作。
当我触摸地图上的注释时,我想更改视图上的文本。
我试过下面的代码,但这不起作用。单击注释图钉时,我只需更改屏幕上的文本。
private func mapView(mapView: MKMapView, didSelect view: MKAnnotationView{
hastane_adi_text.text = "HAstane"
}
Run Code Online (Sandbox Code Playgroud)
你可以在下面看到我的“ViewControllerClass”。
import UIKit
import MapKit
import CoreLocation
class HospitalControlloer: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate{
@IBOutlet weak var hastane_adi_text: UILabel!
@IBOutlet weak var map: MKMapView!
@IBOutlet weak var randevu_al_button: UIButton!
@IBOutlet weak var hizala_button: UIButton!
let locationMenager = CLLocationManager()
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func viewDidLoad() {
super.viewDidLoad()
randevu_al_button.layer.cornerRadius = 10;
hizala_button.layer.cornerRadius = 10;
let locationS:CLLocationCoordinate2D = CLLocationCoordinate2DMake(41.169425, 29.056801)
let sd = MKPointAnnotation()
sd.coordinate = …Run Code Online (Sandbox Code Playgroud) 我似乎无法找到我的问题的最佳答案。
我有这个“OK”但不知道的代码
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
print(mapView.camera.altitude)
if mapView.camera.altitude < 800.00 && !modifyingMap
{
modifyingMap = true
mapView.camera.altitude = 800.00
modifyingMap = false
}
}
Run Code Online (Sandbox Code Playgroud)
我想在我的应用程序中将用户的最大和最小缩放限制到我的地图。
非常感谢任何指向 SO 答案的链接!
谢谢!
我试图检索一个MKRoute包含多条路线的数组,这些路线都从同一个地方开始,但每条路线都有不同的目的地。
问题是我能想出的唯一方法是通过递归函数,但我找不到任何关于如何使用带有完成块的递归函数的信息。由于加载路由是异步完成的,因此需要一个完成块。
我如何获得以下功能但带有完成块?“添加到退货”功能?
func factorial(of num: Int) -> Int {
if num == 1 {
return 1
} else {
return num * factorial(of:num - 1)
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的功能代码
func getDirections(originCoordinate: CLLocationCoordinate2D, destinationCoordinates: [CLLocationCoordinate2D], completion: @escaping(_ routes:[MKRoute]?, _ error: Error?) -> Void) {
// Origin is the same for each route, what changes is the destination
// A singular origin coordinate with an array of destination coordinates is passed in
// The function would in theory be recursive, …Run Code Online (Sandbox Code Playgroud) 我正在使用 swiftui,我想显示指南针按钮。我的代码的地图部分源自本教程:https : //www.morningswiftui.com/blog/build-mapview-app-with-swiftui
我查看了示例代码以在地图上显示指南针,但我找不到可以使用 swiftui 代码的示例。
我有一个 SwiftUI 应用程序,其中有几个视图是使用 UIViewRepresentable 制作的 MapKit 地图。我有兴趣点的自定义注释,并使用左右标注按钮进行进一步操作。在右侧,我只想显示有关航点的信息。在左侧,我想通过选择进一步的操作来发出警报 - 例如,插入一个新的注释点。在 SwiftUI 之前,我只是提出了一个警报并执行了上述两项操作。但据我所知, UIViewRepresentable 版本上没有 self.present 。因此,我无法显示警报。
仅用于实验 - 我将 SwiftUI 警报代码附加到调用 MapView 的 SwiftUI 视图。使用 Observable 布尔值,我确实可以同时发出这些警报。这对我来说似乎很奇怪,但也许绑定到全局属性的警报代码可以在任何地方。
我的第一次尝试:(结构是 DetailMapView)
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == view.leftCalloutAccessoryView {
guard let tappedLocationCoord = view.annotation?.coordinate else {return}
let tappedLocation = CLLocation(latitude: tappedLocationCoord.latitude, longitude: tappedLocationCoord.longitude)
let ac = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
let deleteAction = UIAlertAction(title: "Delete Waypoint", style: .destructive) { (action) in
//some stuff …Run Code Online (Sandbox Code Playgroud) mapkit ×10
ios ×8
swift ×4
iphone ×2
swiftui ×2
annotations ×1
apple-maps ×1
mapbox ×1
mkdirection ×1
mkmapview ×1
mkoverlay ×1
objective-c ×1
recursion ×1
swift3 ×1
uiscrollview ×1
uiview ×1
xcode ×1