I’m working on a Flutter application that utilizes Google Maps. In my app, I have two markers: one representing the user’s location and the other representing the pet’s location. I want to set the zoom level of the map so that both markers are visible on the screen at the same time. How can I calculate the appropriate zoom level to achieve this?
I have the latitude and longitude coordinates for both the user and the pet. Currently, I’m setting the initial camera position like this:
GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(userLatitude, userLongitude),
zoom: 15.0, // Placeholder zoom level
),
markers: _markers, // Set of markers containing user and pet markers
// Other map configurations...
)
However, this approach may not always ensure that both markers are visible, especially if they are far apart or close together.
I’m looking for a solution to dynamically calculate the zoom level based on the distance between the two markers, ensuring that both markers are visible on the screen without requiring the user to scroll.
Could someone provide guidance on how to achieve this in Flutter using the Google Maps plugin?
Thank you for your assistance