【问题标题】:how can I fetch the longitude and latitude from a specific point on my mapview in swift?如何快速从我的地图视图上的特定点获取经度和纬度?
【发布时间】:2016-05-12 01:07:31
【问题描述】:

我的应用中有一个MKMapView,目前我正在使用以下方法获取此地图的中心点:

longitude = mapView.centerCoordinate.longitude
latitude = mapView.centerCoordinate.latitude

但现在我不想取地图的中心点,而是取一个位于地图视图顶部边缘下方 100 像素的特定点。所以通常我会使用类似的东西:

longitude = mapView.centerCoordinate.longitude
latitude = mapView.(centerCoordinate+100px).latitude

但这显然不是这样的。有没有办法从 mkmapview 中获取特定点?

【问题讨论】:

    标签: ios swift mkmapview mapkit mkmapviewdelegate


    【解决方案1】:

    试试这个:

    let frame = mapView.frame
    let myPoint = CGPointMake(frame.midX, 100)
    let myCoordinate = mapView.convertPoint(myPoint, toCoordinateFromView: mapView)
    
    let annotation = MKPointAnnotation()
    annotation.coordinate = myCoordinate
    annotation.title = "My Point"
    
    mapView.addAnnotation(annotation)
    

    【讨论】:

      【解决方案2】:

      使用了 MapKit 方法:

      convertPoint:toCoordinateFromView:
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多