2

I'm trying to draw a dotted polyline on GMSMapView. What I've achieved so far is to add a dashed polyline on the map. For which I've written below code:

polyLine.strokeWidth = 10
polyLine.strokeColor = UIColor(red: 95/255, green: 89/255, blue: 89/255, alpha: 1.0)
let styles: [GMSStrokeStyle] = [GMSStrokeStyle.solidColor(UIColor.clear), GMSStrokeStyle.solidColor(UIColor.red)]
let scale = 1.0 / testMap.projection.points(forMeters: 1, at: testMap.camera.target)
let solidLine = NSNumber(value: 10.0 * Float(scale))
let gap = NSNumber(value: 10.0 * Float(scale))        
let span = GMSStyleSpans(polyLine.path!, styles, [solidLine, gap], GMSLengthKind.rhumb)        
polyLine.spans = span

With this code, I'm getting a polyline with 10x10 squares as dashes.

For dotted polyline I've tried to set the dot image as one of the solid color in GMSStrokeStyle like below:

let styles: [GMSStrokeStyle] = [GMSStrokeStyle.solidColor(UIColor(patternImage: UIImage(named: "dot1.jpg")!)), GMSStrokeStyle.solidColor(UIColor.red)]

One more solution I've tried for the same is here

With this solution, the map takes significant amount of time to load and refresh. Because of which the application hangs on loading the map.

What are other approaches to draw a Dotted Polyline on Google Map in ios?

Keyur Tailor
  • 424
  • 3
  • 16
  • to avoid lagging and handing issue, you can update polyline on "idleAt " instead of "didChange". – Jay Thakkar Mar 15 '19 at 08:00
  • Yes. We can definitely use "idleAt" function. But how can we solve the hanging issue on initial map loading? With more than 5 locations on map, It is taking a good 25 seconds of delay to load the map initially. – Keyur Tailor Mar 15 '19 at 08:11

0 Answers0