This commit is contained in:
Hamza-Ayed
2023-08-15 14:12:20 +03:00
parent 84ab0e86dd
commit 65ade9c874
19 changed files with 619 additions and 166 deletions

View File

@@ -1,5 +1,5 @@
import 'dart:convert';
import 'dart:math' show sqrt, pi, cos, sin;
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
@@ -10,6 +10,8 @@ import 'package:ride/constant/links.dart';
import 'package:ride/controller/functions/crud.dart';
import 'package:ride/views/home/map_widget.dart/buttom_sheet_map_show.dart';
import '../../models/model/locations.dart';
class MapController extends GetxController {
bool isloading = true;
TextEditingController placeController = TextEditingController();
@@ -35,6 +37,9 @@ class MapController extends GetxController {
bool isPickerShown = false;
bool isButtomSheetShown = false;
double heightButtomSheetShown = 240;
late final LatLng southwest;
late final LatLng northeast;
List<CarLocationModel> carLocations = <CarLocationModel>[];
void changeButtomSheetShown() {
isButtomSheetShown = !isButtomSheetShown;
@@ -169,10 +174,22 @@ class MapController extends GetxController {
}
Future getCarsLocationByPassenger() async {
LatLngBounds bounds =
calculateBounds(mylocation.latitude, mylocation.longitude, 10);
print(
'Southwest: ${bounds.southwest.latitude}, ${bounds.southwest.longitude}');
print(
'Northeast: ${bounds.northeast.latitude}, ${bounds.northeast.longitude}');
var res =
await CRUD().get(link: AppLink.getCarsLocationByPassenger, payload: {});
await CRUD().get(link: AppLink.getCarsLocationByPassenger, payload: {
'southwestLat': southwest.latitude.toString(),
'southwestLon': southwest.longitude.toString(),
'northeastLat': northeast.latitude.toString(),
'northeastLon': northeast.longitude.toString(),
});
var data = jsonDecode(res);
print(data);
// print(data);
for (var i = 0; i < data.length; i++) {
carsLocationByPassenger.add(LatLng(
double.parse(data['message'][i]['latitude']),
@@ -182,6 +199,23 @@ class MapController extends GetxController {
update();
}
LatLngBounds calculateBounds(
double centerLat, double centerLng, double radius) {
double radius = 2000; // 10 km in meters
southwest = LatLng(
centerLat - (radius / 111000),
centerLng - (radius / (111000 * cos(centerLat))),
);
northeast = LatLng(
centerLat + (radius / 111000),
centerLng + (radius / (111000 * cos(centerLat))),
);
return LatLngBounds(southwest: southwest, northeast: northeast);
}
GoogleMapController? mapController;
void onMapCreated(GoogleMapController controller) {
mapController = controller;
@@ -395,7 +429,7 @@ class MapController extends GetxController {
void onInit() async {
// getPolyLine();
// getMap();
getLocation();
await getLocation();
await getCarsLocationByPassenger();
addCustomPicker();
addCustomCarIcon();