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

@@ -3,8 +3,14 @@ import 'dart:convert';
class AppCredintials {
static const String basicAuthCredentials = 'hamzaayedphp:malDEV@2101';
static const String serverAPI = 'fgdgf';
// AIzaSyCyfwRXTwSTLOFQSQgN5p7QZgGJVZnEKq0
static const String mapAPIKEY = 'AIzaSyCyfwRXTwSTLOFQSQgN5p7QZgGJVZnEKq0';
//AIzaSyDf_9y315-15v416-_5a536-b24164b31456
//AIzaSyC4y2434-h13-c4y2434-h13-c4y2434-h13
// AIzaSyD10234567890AB123CDEF
// AIzaSyDf416u6_y2-2g_2-Q4d-a74r3-4v83-4h8
// AIzaSyD_d6x8a1r2-527-37-43-43-56-37
//
String getBasicAuthCredentials() {
return base64Encode(utf8.encode(basicAuthCredentials));
}

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.]+'), '');

View File

@@ -4,6 +4,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:ride/constant/colors.dart';
import 'package:ride/controller/home/map_page_controller.dart';
import '../../constant/style.dart';
class MapPage extends StatelessWidget {
const MapPage({super.key});
@@ -17,7 +19,7 @@ class MapPage extends StatelessWidget {
GoogleMap(
onMapCreated: controller.onMapCreated,
cameraTargetBounds: CameraTargetBounds(controller.boundsdata),
minMaxZoomPreference: const MinMaxZoomPreference(12, 18),
minMaxZoomPreference: const MinMaxZoomPreference(6, 18),
onLongPress: (argument) {
Get.defaultDialog(
title: 'Are you want to go to this site',
@@ -26,10 +28,10 @@ class MapPage extends StatelessWidget {
Text('${argument.latitude},${argument.longitude}'),
],
),
onConfirm: () {
onConfirm: () async {
controller.clearpolyline();
controller.getMap(
'${controller.mylocation.latitude}, ${controller.mylocation.longitude}',
await controller.getMap(
'${controller.mylocation.latitude},${controller.mylocation.longitude}',
'${argument.latitude.toString()},${argument.longitude.toString()}');
Get.back();
@@ -131,6 +133,15 @@ class MapPage extends StatelessWidget {
],
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
height: 130,
color: AppColor.secondaryColor,
child:null)
)
],
),
),