【问题标题】:Draw Dashed Circle on Google Maps : iOS在谷歌地图上画虚线圆:iOS
【发布时间】:2017-12-06 18:01:18
【问题描述】:

我一直在努力在 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()
    }
}

这是必需的:

【问题讨论】:

    标签: ios objective-c google-maps swift3


    【解决方案1】:

    使用 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
    

    【讨论】:

    • 太棒了……太棒了……!!它完成了这项工作,非常感谢你..我实际上已经失去了所有的希望..
    猜你喜欢
    • 2018-11-17
    • 2014-09-17
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多