如何在必应地图上用手指绘制折线和多边形?

问题描述 投票:0回答:1

我正在 iOS/Swift 中开发社交媒体应用程序,我需要实现 Bing 地图,以便用户可以通过在 Bing 地图上拖动手指在任何地方绘制或擦除地理围栏(折线和多边形)。

如何绘制和获取多边形的动态坐标?

我正在实现这些代码,但这段代码采用静态坐标(纬度和经度)来绘制形状。

func drawLineOnMap() {
    let center = self.mapView.mapCenter.position

    let geopath = MSGeopath(positions:
        [MSGeoposition(latitude: center.latitude-0.0005, longitude: center.longitude-0.001),
         MSGeoposition(latitude: center.latitude+0.0005, longitude: center.longitude+0.001)])

    let mapPolyline = MSMapPolyline()
    mapPolyline.path = geopath
    mapPolyline.strokeColor = UIColor.black
    mapPolyline.strokeWidth = 3
    mapPolyline.strokeDashed = true

    // Add Polyline to a layer on the map control.
    let linesLayer = MSMapElementLayer()
    linesLayer.zIndex = 1
    linesLayer.elements.add(mapPolyline)
    mapView.layers.add(linesLayer)
}
ios swift bing-maps
1个回答
0
投票

如果我正确理解你的问题,你想要的方法是 MapView 类上的 LocationFromOffset 和 OffsetFromLocation。请参阅此处的文档: https://learn.microsoft.com/en-us/bingmaps/sdk-native/map-control-api/mapview-class 这些方法将从屏幕空间转换为世界坐标,然后您可以使用它来创建 MapPolyline 或 MapPolygon 对象。

© www.soinside.com 2019 - 2024. All rights reserved.