Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change map type on map view?

Tags:

mapkit

swiftui

I am adding a map view like this:

Map(coordinateRegion: $coordinateRegion)
      .frame(height: 400, alignment: .center)
      .cornerRadius(5)
      .shadow(radius: 4)

Map shows up as this:

enter image description here

I want to allow the user to change the map type (satellite, etc...).

Is there a way to set the map type in SwiftUI?

like image 507
zumzum Avatar asked Oct 14 '25 07:10

zumzum


2 Answers

As for now I fear that you have to access the mapType using

MKMapView.appearance().mapType = .satellite // or any other map type

You can use it just onAppear. I am not sure if there is a better way, but at least it works :)

For more detailed specifications the UIKit Mapview is needed for now.

like image 80
Bortol15 Avatar answered Oct 18 '25 03:10

Bortol15


You can change the style of the map by using MapStyle like that :

Map {
   // your content
}.mapStyle(.imagery)

You have some styles available :

  • standard : The default options. Only show few roads and some names.
  • imagery : The satellite view only
  • hybrid : A mix of both, the satellite view with some roads, names and others useful stuff
like image 31
Elikill58 Avatar answered Oct 18 '25 03:10

Elikill58



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!