ios - 在谷歌地图上画虚线圆 : iOS
<p><blockquote>
<p><strong>I've been trying so hard to Draw a Dashed Circle on Google Maps but couldn't find anything helping...</strong></p>
</blockquote>
<p>几天来,我一直在网上寻找一些在 GoogleMaps 上绘制虚线圆圈的解决方案,不幸的是,除了绘制一个普通的圆圈之外,我每次都能得到答案。</p>
<p><strong>这就是我所做的:</strong></p>
<p> <a href="/image/Xv5JL.png" rel="noreferrer noopener nofollow"><img src="/image/Xv5JL.png" alt="map with circle"/></a> </p>
<p>上面的代码是:</p>
<pre><code>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()
}
}
</code></pre>
<p><strong>这是必需的:</strong> </p>
<p> <a href="/image/ckrKF.jpg" rel="noreferrer noopener nofollow"><img src="/image/ckrKF.jpg" alt="enter image description here"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>使用 GMSCircle 是不可能的,您必须基于圆绘制折线。</p>
<p>使用 GMSGeometryOffset,您可以生成您所在位置的偏移量。
360/6 = 60,细节更少,效率更高。</p>
<pre><code>let path = GMSMutablePath()
for i in 0...60 {
let offsetLocation = GMSGeometryOffset(location.coordinate, circleRadius, CLLocationDirection(i*6))
path.add(offsetLocation)
}
let length: =
let circle = GMSPolyline(path: path)
let styles =
circle.spans = GMSStyleSpans(circle.path!, styles, length, GMSLengthKind.rhumb)
circle.strokeWidth = 1.0
circle.map = mapView
</code></pre></p>
<p style="font-size: 20px;">关于ios - 在谷歌地图上画虚线圆 : iOS,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/44886053/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/44886053/
</a>
</p>
页:
[1]