SDK Google Maps中的Swift Draw多边形/形状 [英] Swift Draw polygons/shape in SDK Google Maps

查看:162
本文介绍了SDK Google Maps中的Swift Draw多边形/形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Maps SDK在Swift 3.0中开发应用程序.我不得不说这是我第一次使用此SDK,因此需要一点帮助.我想我问你会很容易.我想做的是当用户进入地图编辑模式时(例如此页面 http://www.birdtheme.org/useful/v3tool.html ).他可以做两件事:

I'm developing an application in swift 3.0 with the Google Maps SDK. I have to say this is the first time I work with this SDK and it is so I need a little help. I think what I ask you will be easy for you. What I want to do is when the user enters a map editing mode (like this page http://www.birdtheme.org/useful/v3tool.html ). He can do two things:

  • 首先,他可以在地图上绘制多边形(以标记农民田地的边界).我希望用户按下地图上的一个点并生成一条线,直到下一个点.这样,他将生成线直到多边形闭合. 我的绘制多边形的代码附在下面.但是问题是它永远不会关闭多边形.但是问题是当我要触摸线条的开始和结尾或线条交叉时,我想要它.我该怎么办它?如您在图片中看到的,我可以画出无限的线.

  • First he could draw polygons on the map (to mark the boundaries of a farmer field). I want the user to press a point on the map and generate a line until the next point. In this way, he will generate lines until the polygon is closed. My code for drawing polygon attach below. But the problem is that it never closes the polygon.But the problem is that I want it when the beginning of the line and the end are touched or the lines cross, close the polygon.How do I do it? As you see in the picture, I can draw infinite lines.

let pathEditField = GMSMutablePath()
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {

    if modeEditing {
        pathEditField.add(coordinate)
        let polyline = GMSPolyline(path: pathEditField)
        polyline.map = mapView

    }
}

  • 第二,绘制完多边形后,将以某种方式突出显示顶点,然后可以移动该顶点以完成调整.

    我给您留下了一个屏幕截图,以便您了解用户可以在其中创建多边形以及在何处调整顶点的想法.

    I leave you a screenshot, so that you get an idea where the user can create the polygon and where to adjust the vertices.

    问题是,除了找不到文档外,我不知道该怎么做.我的问题是,您知道做过类似事情的任何教程吗?还是可以不编写代码就直接启动代码?

    用户可以通过创建多边形并随后对其进行调整来确定其地块的范围.

    The user can determine the limits of his land parcel by creating a polygon and adjusting it afterwards.

    非常感谢您.

    推荐答案

    使用此代码创建多边形

    Use this code to create polygon GoogleMaps documentaion

     let camera = GMSCameraPosition.camera(withLatitude: 76.0,
                                              longitude: 87.0,
                                              zoom: 18)
        let mapView = GMSMapView.map(withFrame: .zero, camera: camera)
    
        let path = GMSMutablePath()
        //Add vertex's to Path like as shown bellow
        //get vertices from map
       // https://developers.google.com/maps/documentation/ios-sdk/shapes
    
    let path = GMSMutablePath()
    path.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
    path.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.0))
    path.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.2))
    path.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.2))
    path.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
    
        let polyline = GMSPolyline(path: path)
        polyline.strokeColor = .blue
        polyline.strokeWidth = 5.0
        polyline.map = mapView
    

    这篇关于SDK Google Maps中的Swift Draw多边形/形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆