sbis04 / flutter_maps

A Flutter app using Google Maps SDK, Directions API
MIT License
340 stars 158 forks source link

Wrong calculation of CameraUpdate bounds #1

Closed giohappy closed 4 years ago

giohappy commented 4 years ago

The CameraUpdate for the route is wrong. It always assume the source and destination to be located from southwest to northeast.

The following lines

https://github.com/sbis04/flutter_maps/blob/7a439ee016c4fc1ba621047aa2d0cf624cf5ffb2/lib/main.dart#L204-L210

should be replaced with the following (or similar code):

double miny = (startCoordinates.latitude <= destinationCoordinates.latitude) ? startCoordinates.latitude : destinationCoordinates.latitude;
double minx = (startCoordinates.longitude <= destinationCoordinates.longitude) ? startCoordinates.longitude : destinationCoordinates.longitude;
double maxy = (startCoordinates.latitude <= destinationCoordinates.latitude) ? destinationCoordinates.latitude : startCoordinates.latitude;
double maxx = (startCoordinates.longitude <= destinationCoordinates.longitude) ? destinationCoordinates.longitude : startCoordinates.longitude;

Position _southwestCoordinates = Position(
  latitude: miny,
  longitude: minx
);
Position _northeastCoordinates =  Position(
  latitude: maxy,
  longitude: maxx
);
sardapv commented 4 years ago

thanks man.. thats why my camera was moving to different continent lol..

ntando-zanotech commented 4 years ago

thank you. My problem is sorted now

sbis04 commented 4 years ago

Thanks @giohappy for this solution. I have updated the example as per that.