I've been trying so hard to Draw a Dashed Circle on Google Maps but couldn't find anything helping...
几天来,我一直在网上寻找一些在 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()
}
}
这是必需的:
使用 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
关于ios - 在谷歌地图上画虚线圆 : iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44886053/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |