在Google Maps上绘制虚线圆圈:iOS

Yas*_*edi 3 google-maps objective-c ios swift3

我一直在努力在Google地图上画一个虚线圆圈,但找不到任何帮助...

我一直在互联网上浏览数日,找到了一些在GoogleMaps上绘制虚线圆的解决方案,但我每次都会得到答案,而不是绘制一个普通圆。

这是我所做的:

带圆圈的地图

上面的代码是:

import UIKit
import GoogleMaps
import GooglePlaces

class ViewController: UIViewController
{
    @IBOutlet weak var gmsMapView: GMSMapView!

    override func viewDidLoad()
    {
        super.viewDidLoad()

        gmsMapView.isMyLocationEnabled = true
        gmsMapView.settings.myLocationButton = true
        gmsMapView.animate(toZoom: 10.0)
        gmsMapView.animate(toLocation: CLLocationCoordinate2D(latitude: 40.709677, longitude: -74.011088))
        let circleCenter = CLLocationCoordinate2D(latitude: 40.709677, longitude: -74.011088)
        let circle = GMSCircle(position: circleCenter, radius: 5000)
        circle.strokeWidth = 2
        circle.strokeColor = UIColor.blue
        circle.map = gmsMapView
    }

    override func didReceiveMemoryWarning(){
        super.didReceiveMemoryWarning()
    }
}
Run Code Online (Sandbox Code Playgroud)

这是必需的:

在此处输入图片说明

小智 6

使用GMSCircle不可能,您必须基于圆画一条折线。

使用GMSGeometryOffset,您可以生成位置的偏移量。360/6 = 60,效率更低。

let path = GMSMutablePath()

for i in 0...60 {
    let offsetLocation = GMSGeometryOffset(location.coordinate, circleRadius, CLLocationDirection(i*6))
    path.add(offsetLocation)
}
let length: [NSNumber] = [10, 10]
let circle = GMSPolyline(path: path)
let styles = [GMSStrokeStyle.solidColor(.clear), GMSStrokeStyle.solidColor(.red)]

circle.spans = GMSStyleSpans(circle.path!, styles, length, GMSLengthKind.rhumb)
circle.strokeWidth = 1.0
circle.map = mapView
Run Code Online (Sandbox Code Playgroud)