Dotted polyline on Google Maps IOS-Swift

Related searches

I want to draw a dotted polyline on Google Maps using swift language, can anyone to help me?

private var polylineArray:[GMSCircle] = [GMSCircle]() //global variable

//MARK: Find a route between to coordinates and draw the route

private func callingDistanceAPI() {
   let origin = "\(37.778483),\(-122.513960)"
   let destination = "\(37.706753),\(-122.418677)"
   let url = "\(origin)&destination=\(destination)&mode=driving&key=[YOUR-API-KEY]"

Alamofire.request(url).responseJSON { response in
   guard let data = response as? [String:Any],
            let preRoutes = data["routes"] as? NSArray,
            let preRoute = preRoutes.firstObject,
            let routes = preRoute as? NSDictionary,
            let routeOverviewPolyline:NSDictionary = routes.value(forKey: "overview_polyline") as? NSDictionary,
            let polyString = routeOverviewPolyline.object(forKey: "points") as? String else {
      self.showPath(polyStr: polyString)

//MARK: Draw polyline

func showPath(polyStr :String) {
    guard let path = GMSMutablePath(fromEncodedPath: polyStr) else {return}
    //MARK: remove the old polyline from the GoogleMap

    let intervalDistanceIncrement: CGFloat = 10
    let circleRadiusScale = 1 / mapView.projection.points(forMeters: 1, at:
    var previousCircle: GMSCircle?
    for coordinateIndex in 0 ..< path.count() - 1 {
        let startCoordinate = path.coordinate(at: coordinateIndex)
        let endCoordinate = path.coordinate(at: coordinateIndex + 1)
        let startLocation = CLLocation(latitude: startCoordinate.latitude, longitude: startCoordinate.longitude)
        let endLocation = CLLocation(latitude: endCoordinate.latitude, longitude: endCoordinate.longitude)
        let pathDistance = endLocation.distance(from: startLocation)
        let intervalLatIncrement = (endLocation.coordinate.latitude - startLocation.coordinate.latitude) / pathDistance
        let intervalLngIncrement = (endLocation.coordinate.longitude - startLocation.coordinate.longitude) / pathDistance
        for intervalDistance in 0 ..< Int(pathDistance) {
            let intervalLat = startLocation.coordinate.latitude + (intervalLatIncrement * Double(intervalDistance))
            let intervalLng = startLocation.coordinate.longitude + (intervalLngIncrement * Double(intervalDistance))
            let circleCoordinate = CLLocationCoordinate2D(latitude: intervalLat, longitude: intervalLng)
            if let previousCircle = previousCircle {
                let circleLocation = CLLocation(latitude: circleCoordinate.latitude,
                                                longitude: circleCoordinate.longitude)
                let previousCircleLocation = CLLocation(latitude: previousCircle.position.latitude,
                                                        longitude: previousCircle.position.longitude)
                if mapView.projection.points(forMeters: circleLocation.distance(from: previousCircleLocation),
                                             at: < intervalDistanceIncrement {
            let circleRadius = 3 * CLLocationDistance(circleRadiusScale)
            let circle = GMSCircle(position: circleCoordinate, radius: circleRadius)
            circle.strokeWidth = 1.0
            circle.strokeColor =
            circle.fillColor =
   = mapView
            circle.userData = "root"
            previousCircle = circle

    //MARK: - Removing dotted polyline 
    func removePolylinePath() {
    for root: GMSCircle in self.polylineArray {
        if let userData = root.userData as? String,
            userData == "root" {
   = nil

I have taken the reference for drawing the dotted polyline from this link :

Dotted polyline on Google Maps IOS-Swift, private var polylineArray:[GMSCircle] = [GMSCircle]() //global variable //MARK: Find a route between to coordinates and draw the route private� Browse other questions tagged ios swift google-maps or ask your own question. ios Google SDK Map cannot create dotted polylines. Related. 738.

Reference to the following link: that may be of help.

func drawRoute() {
    let route = mapTasks.overviewPolyline["points"] as String

    let path: GMSPath = GMSPath(fromEncodedPath: route)
    routePolyline = GMSPolyline(path: path) = viewMap

At the end of the above snippet, we necessarily have to set the map to the routePolyline property.

func displayRouteInfo() {
    lblInfo.text = mapTasks.totalDistance + "\n" + mapTasks.totalDuration

ios Google SDK Map cannot create dotted polylines, Creating a dashed line in google maps is as simple as this. who needs line segments lengths to be independent of map zoom level, here's my solution in swift. unresolved identifier when creating a dotted Polyline in Google Maps iOS API. Ask Question Asked 2 years, 7 months ago. ios swift xcode google-maps.

As I know is not possible yet :- (. You can draw dashed lines via GMSStyleSpans, but not dotted lines (Google Maps vers. 2.2.0). If I'm wrong please leave a comment.

how to create a dotted polyline in Google Maps with swift 2.0, I've tried this question that has some relevant objC code, but my swift2.0 version only produces dashed (and not dotted) lines. This is my code: let path = // . And finally, set the polylines on the map, provided the source and destination as a pair of latitude and longitude values and the Google Maps API Key to the getRouteBetweenCoordinates method

Dashed Line Symbols (Polyline), Give the line an opacity of 0. // Repeat the symbol at intervals of 20 pixels to create the dashed effect. const line = new google.maps.Polyline({ path: [ { lat: 22.291� polyline.setStartCap(new RoundCap()); break; } polyline.setEndCap(new RoundCap()); polyline.setWidth(POLYLINE_STROKE_WIDTH_PX); polyline.setColor(COLOR_BLACK_ARGB);

Drawing a dashed line on GoogleMaps for iOS � GitHub, Drawing a dashed line on GoogleMaps for iOS. GitHub Gist: instantly GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];. = self. This library tries to have consistent results with polylines generated by the Google Maps iOS SDK. The online tool for encoding polylines has some minor inconsistencies regarding rounding (for example, 0.000015 is rounded to 0.00002 for latitudes, but 0.00001 for longitudes). This codes tries to adhere to the GitHub Swift Style Guide. Contributors

TypeScript // This example creates a 2-pixel-wide red polyline showing the path of // the first trans-Pacific flight between Oakland, CA, and Brisbane, // Australia which was made by Charles Kingsford Smith.

  • i already have this in my code but this code not draw a dotted polyline.