I have an array of latitude & longitude and I want to draw polyline using those data.
Array data are as below,
[
{
address = "Gota, Godrej Garden City Road, Ahmedabad, India, 382481 ",
city = Ahmedabad,
latitude = "23.10104251103548",
longitude = "72.54941169820619",
street = "Godrej Garden City Road",
},
{
address = "Aaryan Eureka Opposite Shayona Shikhar, Vandemataram Rd, Gota, Ahmedabad, Gujarat 382481",
city = Ahmedabad,
latitude = "23.09644251103548",
longitude = "72.54801169820619",
street = "Vandemataram Rd",
},
....// Hundreds of records
]
Code which I tried so far,
let path = GMSMutablePath()
for mapData in arrMapData {
path.add(CLLocationCoordinate2D(latitude: mapData.latitude ?? 0.0, longitude: mapData.longitude ?? 0.0))
}
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 3.0
polyline.strokeColor = .black
polyline.map = mapView // Google MapView
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: arrMapData[0].latitude ?? 0.0, longitude: arrMapData[0].longitude ?? 0.0)
marker.icon = UIImage(named: AppImages.Pin_red)
marker.title = sourceTitle
marker.snippet = sourceSnippet
marker.map = mapView
let marker1 = GMSMarker()
marker1.position = destination
marker1.icon = UIImage(named: AppImages.Map_pin_orange)
marker1.title = destinationTitle
marker1.snippet = destinationSnippet
marker1.map = mapView
I am aware about Google Direction API, but I don't need to call that api because I already have all those latitude and longitude data... And even calling direction api for all hundred records is also not a feasible solution.
My above code not giving me any kind of error. It is plotting two pins on the Map which seems correct to me[Source destination details added from 0th index object from array and last index object from Array].
But no polyline is added on Map. I am looking for some solution to this. Thank you!

mapData.latitudeandmapData.longitudeis number and > 0 - Trai Nguyen