2017-07-03 6 views
0

Ich habe so hart versucht, einen gestrichelter Kreis auf Google Maps zu zeichnen, aber kann nichts helfen, finde ...Draw Dashed Kreis auf Google Maps: iOS

ich bin für Tage über das Internet buchstäblich suchen einige Lösungen für die Erstellung eines eine gestrichelte Kreis auf Googlemaps zu finden, leider andere als eine einfache Kreis Zeichnung ist die Antwort, was ich jedes Mal bekommen ..

Hier ist, was ich getan habe:

map with circle

-Code für die oben ist:

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() 
    } 
} 

Dies ist, was erforderlich ist:

enter image description here

Antwort

1

Mit GMSCircle es nicht möglich, müssen Sie eine Polylinie zeichnen Basis auf einem Kreis.

Mit GMSGeometryOffset können Sie einen Offset zu Ihrem Standort generieren. 360/6 = 60 für weniger Details eine Effizienz.

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 
+0

Wunderbare ... Awesome .. !! Es hat den Job vielen Dank gemacht. Ich hatte wirklich alle Hoffnungen verloren. –

+0

Können wir sie im Kreis bekommen .. ?? Ich meine diese Striche .. –