I trying to add the location of schedule as mapmarks on map of MapKit, and connect them order by time.
But the Path didn’t show up, and I sure that the start
and end
are at the right position. So I wonder is the Path not allowed to overight the MapView? If so. How do I implement this?
<code>ZStack{
Map(coordinateRegion: $region, annotationItems: markList) { location in
MapMarker(coordinate: CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude), tint: .red)
}
.frame(height: proxyHight * 0.35)
.padding([.leading, .trailing], 22)
.cornerRadius(20)
.shadow( radius: 3, x: 3, y: 3)
Path { path in
// Draw dotted lines between markers
for (index, location) in markList.enumerated() {
if index < markList.count - 1 {
let nextLocation = markList[index + 1].coordinate
let start = CGPoint(x: location.coordinate.longitude, y: location.coordinate.latitude)
let end = CGPoint(x: nextLocation.longitude, y: nextLocation.latitude)
//print("Drawing line from (start) to (end)")
path.move(to: start)
path.addLine(to: end)
}
}
}
.stroke(style: StrokeStyle(lineWidth: 2, dash: [5]))
.foregroundColor(Color.blue)
}
</code>
<code>ZStack{
Map(coordinateRegion: $region, annotationItems: markList) { location in
MapMarker(coordinate: CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude), tint: .red)
}
.frame(height: proxyHight * 0.35)
.padding([.leading, .trailing], 22)
.cornerRadius(20)
.shadow( radius: 3, x: 3, y: 3)
Path { path in
// Draw dotted lines between markers
for (index, location) in markList.enumerated() {
if index < markList.count - 1 {
let nextLocation = markList[index + 1].coordinate
let start = CGPoint(x: location.coordinate.longitude, y: location.coordinate.latitude)
let end = CGPoint(x: nextLocation.longitude, y: nextLocation.latitude)
//print("Drawing line from (start) to (end)")
path.move(to: start)
path.addLine(to: end)
}
}
}
.stroke(style: StrokeStyle(lineWidth: 2, dash: [5]))
.foregroundColor(Color.blue)
}
</code>
ZStack{
Map(coordinateRegion: $region, annotationItems: markList) { location in
MapMarker(coordinate: CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude), tint: .red)
}
.frame(height: proxyHight * 0.35)
.padding([.leading, .trailing], 22)
.cornerRadius(20)
.shadow( radius: 3, x: 3, y: 3)
Path { path in
// Draw dotted lines between markers
for (index, location) in markList.enumerated() {
if index < markList.count - 1 {
let nextLocation = markList[index + 1].coordinate
let start = CGPoint(x: location.coordinate.longitude, y: location.coordinate.latitude)
let end = CGPoint(x: nextLocation.longitude, y: nextLocation.latitude)
//print("Drawing line from (start) to (end)")
path.move(to: start)
path.addLine(to: end)
}
}
}
.stroke(style: StrokeStyle(lineWidth: 2, dash: [5]))
.foregroundColor(Color.blue)
}