each one i attempted a number of methodology however there’s at all times hole b/w my poly line and drawn marker the place my route finish. i wish to draw dotted path the hole b/w my polyline and marker i additionally tried strolling url however nonetheless it doesnot work please assist how am i able to fill this hole that at all times right here what ever. lat and lengthy. i take advantage of for. each polyy liine and marker settup[enter image description here](https://i.stack.imgur.com/cHg30.png) black one for driving and inexperienced one for strolling
extension MapViewController: SetUpLocationDisplayLogic {
func mapRouteSetup(startlatitude: Double, startlongitude: Double, endlatitude: Double, endlongitude: Double) {
let apiKey = “AIzaSyBsdpz4AX5T6uqLxqJXUgEDtoxd0TIiJ2w”
// Outline the URLs for strolling and driving routes
let walkingRequestURL = "https://maps.googleapis.com/maps/api/instructions/json?origin=(startlatitude),(startlongitude)&vacation spot=(endlatitude),(endlongitude)&mode=strolling&key=(apiKey)"
let drivingRequestURL = "https://maps.googleapis.com/maps/api/instructions/json?origin=(startlatitude),(startlongitude)&vacation spot=(endlatitude),(endlongitude)&key=(apiKey)"
// Make API requests for each strolling and driving routes
URLSession.shared.dataTask(with: URL(string: walkingRequestURL)!) { (information, response, error) in
if let information = information {
// Parse and draw strolling route
self.drawWalkingRoute(information: information)
} else if let error = error {
print("Error making the strolling route API request: (error)")
}
}.resume()
URLSession.shared.dataTask(with: URL(string: drivingRequestURL)!) { (information, response, error) in
if let information = information {
// Parse and draw driving route
self.drawDrivingRoute(information: information)
} else if let error = error {
print("Error making the driving route API request: (error)")
}
}.resume()
}
func drawWalkingRoute(information: Information) {
if let path = createPathFromRouteData(information) {
DispatchQueue.primary.async {
// Create a GMSPolyline for the strolling route
let polyline = GMSPolyline(path: path)
polyline.strokeColor = .appColor(.x8DC63F) // Customise the colour as wanted
polyline.strokeWidth = 10.0 // Customise the width as wanted
polyline.map = self.mapView
}
}
}
func drawDrivingRoute(information: Information) {
if let path = createPathFromRouteData(information) {
DispatchQueue.primary.async {
// Create a GMSPolyline for the driving route
let polyline = GMSPolyline(path: path)
polyline.strokeColor = .appColor(.x434343) // Customise the colour as wanted
polyline.strokeWidth = 10.0 // Customise the width as wanted
polyline.map = self.mapView
}
}
}
func createPathFromRouteData(_ routeData: Information) -> GMSPath? {
do {
let jsonObject = attempt JSONSerialization.jsonObject(with: routeData, choices: [])
if let jsonDict = jsonObject as? [String: Any],
let routes = jsonDict["routes"] as? [[String: Any]],
let firstRoute = routes.first,
let overviewPolyline = firstRoute["overview_polyline"] as? [String: Any],
let factors = overviewPolyline["points"] as? String {
let path = GMSPath(fromEncodedPath: factors)
return path
}
} catch {
print("Error parsing route information: (error)")
}
return nil
}
func didFindLocation(startaddress: String, endaddress: String, startlatitude: Double, startlongitude: Double, endlatitude: Double, endlongitude: Double) {
DispatchQueue.primary.async { [weak self] in
self?.startingTextField.textual content = startaddress
self?.endingTextField.textual content = endaddress
let digital camera = GMSCameraPosition.digital camera(
withLatitude: startlatitude,
longitude: startlongitude,
zoom: 12.0
)
self?.mapView.digital camera = digital camera
let firstMarkerPosition = CLLocationCoordinate2D(
latitude: startlatitude,
longitude: startlongitude
)
self?.showMarker(
place: firstMarkerPosition,
title: "First Location",
snippet: "One other Location",
icon: (self?.customMarkerImage ?? self?.placeHolder)!
)
let secondMarkerPosition = CLLocationCoordinate2D(
latitude: endlatitude,
longitude: endlongitude
)
self?.showMarker(
place: secondMarkerPosition,
title: "Second Location",
snippet: "One other Location",
icon: (self?.customMarkerImage ?? self?.placeHolder)!
)
// Name the mapRouteSetup perform with the offered latitude and longitude
self?.mapRouteSetup(startlatitude: startlatitude, startlongitude: startlongitude, endlatitude: endlatitude, endlongitude: endlongitude)
}
}
}