Post not yet marked as solved
Hi everybody, in my app I have a button that open a destination in maps, the problem is that after maps launching, the destination is unknown location , is possible to make it appear with the name and the information provided by maps?This is my situationand this is what I would dois it possible?this is my codeimport SwiftUI
import CoreLocation
import MapKit
import Contacts
var body: some View {
HStack {
MapView()
Button(action: {MapView().openMaps()}) {
Text("GO!")
}
}
}
func openMaps() {
let coordinate = CLLocationCoordinate2D(latitude: 41.928435, longitude: 12.466579)
let placemark = MKPlacemark(coordinate: coordinate)
let mapItem = MKMapItem(placemark: placemark)
mapItem.openInMaps()
}
Post not yet marked as solved
Hi, I'm trying to change the pin color of my mapView, is it possible?This is my code for nowimport SwiftUI
import MapKit
struct MapView: UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
MKMapView(frame: .zero)
}
func updateUIView(_ view: MKMapView, context: Context) {
let coordinate = CLLocationCoordinate2D(latitude: 41.928725, longitude: 12.466310)
let span = MKCoordinateSpan(latitudeDelta: 0.0075, longitudeDelta: 0.0075)
let region = MKCoordinateRegion(center: coordinate, span: span)
view.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
annotation.title = "Visit us soon"
view.addAnnotation(annotation)
}
}
struct MapView_Previews: PreviewProvider {
static var previews: some View {
MapView()
}
}
Post not yet marked as solved
Hi guys, while in subView It's possible to navigate back to first view tapping on the tab bar item?This is my codestruct ContentView: View {
@State private var selection = 0
var body: some View {
TabView(selection: $selection){
firstView()
.tabItem {
VStack {
Image("first")
Text("first")
}
}
.tag(0)
secondView()
.tabItem {
VStack {
Image("second")
Text("second")
}
}
.tag(1)
}
}
}
//code of firstView
struct firstView: View {
var body: some View {
NavigationView {
NavigationLink(destination: subView()){
Text("go to subView")
}
}
}
Why does my swiftUI app crash when navigating backwards after placing a NavigationLink insiede of a NavigationBarItems?NavigationView {
Text("Hello World")
.navigationBarItems(
trailing: NavigationLink(destination: Child()) {
Image("myImageName"})
}