liveview-native / liveview-native-swiftui-mapkit

MapKit addon library for LiveView Native
1 stars 1 forks source link

lat/lon deltas aren't working #208

Closed bcardarella closed 5 months ago

bcardarella commented 5 months ago

I have the following:

    <Map
      bounds:latitude={34.011_286}
      bounds:longitude={-116.166_868}
      bounds:latitude-delta={0.2}
      bounds:longitude-delta={0.2}
      />

and it should render this:

image

but instead I get this:

Screenshot 2024-01-21 at 8 04 21 PM

I believe the location is working as when I change the lat/lon values it will center on the correct location.

When I look at the View Hierarchy I see the deltas present:

Screenshot 2024-01-21 at 8 07 46 PM

It's not clear to me why the deltas are not working to zoom the map

bcardarella commented 5 months ago

I did render the map correct in SwiftUI with:

import SwiftUI
import MapKit

struct ContentView: View {
    var body: some View {
        Map(initialPosition: .region(region))
    }

    private var region: MKCoordinateRegion {
            MKCoordinateRegion(
                center: CLLocationCoordinate2D(latitude: 34.011_286, longitude: -116.166_868),
                span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2)
            )
        }
}

which renders as expected in the first image above. The MapContentView in the View Hierarchy looks different too:

Screenshot 2024-01-21 at 8 28 23 PM
bcardarella commented 5 months ago

This might be helpful, the issue I don't believe is the max/min bounds but the default zoom. See the video of the LVN render: https://www.youtube.com/watch?v=Ip_pDOj931I

the bounds appear to be in place so whatever default Zoom that example I have appears to be doing something different

carson-katri commented 5 months ago

Instead of setting the bounds you'll need to set the position. It needs to be JSON encoded:

<Map
  position={Jason.encode!(%{ type: :region, center: [34.011_286, -116.166_868], latitude_delta: 0.2, longitude_delta: 0.2 })}
/>
bcardarella commented 5 months ago

@carson-katri I think we'll need to change this approach. Using json encoding within LVs isn't great for values that could be expected to rapidly change like map positions.

Something like this would be nice:

<Map
  position:type="region"
  position:center-latitude={34.011_286}
  position:center-longitude={-116.166_868}
  position:latitude-delta={0.2}
  position:longitude-delta={0.2}
/>
bcardarella commented 5 months ago

Fixed in #209