This commit is contained in:
Hamza Aleghwairyeen
2023-08-07 13:30:20 +03:00
parent 1b79e49872
commit ab10da4623
14 changed files with 484 additions and 62 deletions

View File

@@ -107,10 +107,10 @@ class MapController extends GetxController {
(_locationData.latitude != null && _locationData.longitude != null
? LatLng(_locationData.latitude!, _locationData.longitude!)
: null)!;
// print(currentLocation.accuracy);
// print(currentLocation.latitude);
// print(currentLocation.time);
// print('//////////////////////////////////////');
print(_locationData.accuracy);
print(_locationData.latitude);
print(_locationData.time);
print('//////////////////////////////////////');
update();
}
@@ -118,6 +118,9 @@ class MapController extends GetxController {
void onMapCreated(GoogleMapController controller) {
mapController = controller;
controller.getVisibleRegion();
// controller.animateCamera(
// CameraUpdate.newLatLng(mylocation),
// );
update();
}
@@ -154,34 +157,21 @@ class MapController extends GetxController {
LatLngBounds boundsData =
LatLngBounds(northeast: northeast, southwest: southwest);
// Calculate padding for the bounding box
double distance = math.sqrt(
math.pow(northeast.latitude - southwest.latitude, 2) +
math.pow(northeast.longitude - southwest.longitude, 2),
);
// Define the map padding
final double padding = 50.0;
// Get the screen dimensions
final screenSize = Get.size;
print(screenSize.width);
print('================');
// Adjust the bounding box to include padding
LatLngBounds adjustedBounds = LatLngBounds(
southwest: LatLng(boundsData.southwest.latitude - padding,
boundsData.southwest.longitude - padding),
northeast: LatLng(boundsData.northeast.latitude + padding,
boundsData.northeast.longitude + padding),
);
// Calculate the zoom level based on the distance and screen size
double zoomLevel = getZoomLevel(distance, screenSize.width);
// Animate the camera to the adjusted bounds
mapController!.animateCamera(CameraUpdate.newLatLngBounds(
adjustedBounds,
screenSize.width,
));
double distanceOfDestnation =
getDistanceFromText(data[0]['distance']['text']);
// Animate the camera to the adjusted bounds
if (distanceOfDestnation > 16 && distanceOfDestnation < 30) {
mapController!.animateCamera(CameraUpdate.newLatLngZoom(mylocation, 10));
} else if (distanceOfDestnation > 30 && distanceOfDestnation < 100) {
mapController!.animateCamera(CameraUpdate.newLatLngZoom(mylocation, 8));
} else if (distanceOfDestnation > 100) {
mapController!.animateCamera(CameraUpdate.newLatLngZoom(mylocation, 6));
} else {
mapController!.animateCamera(CameraUpdate.newLatLngZoom(mylocation, 11));
}
if (polylines.isNotEmpty) {
clearpolyline();
} else {
@@ -197,17 +187,6 @@ class MapController extends GetxController {
}
}
double getZoomLevel(double distance, double screenWidth) {
const double zoomFactor = 15.0;
const double pixelRatio =
156543.03392; // Earth circumference in pixels at zoom level 0
double zoomLevel =
(math.log(pixelRatio * screenWidth / (distance * zoomFactor))) /
math.log(2);
return zoomLevel;
}
double getDistanceFromText(String distanceText) {
// Remove any non-digit characters from the distance text
String distanceValue = distanceText.replaceAll(RegExp(r'[^0-9.]+'), '');