我一直在努力在谷歌地图上画一个虚线圆圈,却找不到任何帮助...
我几天来一直在互联网上寻找一些在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()
}
}
这是必需的:
答案 0 :(得分: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