Skip to content

Append a Text after an Image as ViewMapAnnotation not showed #47

@Nickbarbieri1

Description

@Nickbarbieri1

I'm trying to use Map library to implement a Map where is showed some ViewMapAnnotation, as much as the user wants to show, but I'm not able to show a simple Text under the Image that represents the single annotation

This is my code for the map implementation:

Map(coordinateRegion: $searchService.region,
type: selectedMapStyle,
pointOfInterestFilter: .excludingAll,
informationVisibility: .default.union(.userLocation),
interactionModes: .all,
userTrackingMode: $userTracking,
annotationItems: selectedLandmark,
annotationContent: { location in
ViewMapAnnotation(coordinate: location.coordinate, title: location.name) {
VStack{
Image(systemName: "mappin.circle.fill")
.foregroundColor(.red)
.font(.title)
.padding()

                            Text("\(location.name)")
                                .font(.caption2)
                        }
                    }
                },
                    overlays:  renderRoutes.map {$0.polyline},
                    overlayContent: {overlay in
                    RendererMapOverlay(overlay: overlay) {_, overlay in
                        guard let polyline = overlay as? MKPolyline else {
                            assertionFailure("Unknown overlay type encountered!")
                            return MKOverlayRenderer(overlay: overlay)
                        }
                        let isAndataRoute = polyline === andataRoutes.first?.polyline
                        let renderer = MKPolylineRenderer(polyline: polyline)
                        renderer.lineWidth = 4
                        renderer.strokeColor = isAndataRoute ? .systemBlue : .systemCyan
                        updateRectRegion(rectangle: overlay.boundingMapRect)
                        return renderer
                    }
                }
                )
                .ignoresSafeArea()
                .background(
                    RoundedRectangle(cornerRadius: 30)
                )

I really hope that someone can help me because this is a project that I'm developing for the final exam at university 😄
P.S. Sorry, but I'm not able to use properly the code function of GitHub because every time that I paste the code, GitHub adds to it a lot of tab at the beginning of every line

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions