new changes maps
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
||||
import 'dart:async';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'dart:io';
|
||||
@@ -22,8 +21,10 @@ import 'package:nearle/controllers/delivery.dart';
|
||||
import 'package:nearle/controllers/deliveries_controller.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:slide_to_submit_button/slide_to_submit_button.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:geocoding/geocoding.dart';
|
||||
import 'package:nearle/services/maps/map_marker_icons.dart';
|
||||
import 'package:nearle/services/maps/nearle_map.dart';
|
||||
import 'package:nearle/services/maps/routing_service.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:floating/floating.dart';
|
||||
import 'dart:math' as math;
|
||||
@@ -2624,7 +2625,6 @@ void _showmapDetailsSheet(
|
||||
double pickupLat = parseD(pickupLatStr);
|
||||
double pickupLng = parseD(pickupLngStr);
|
||||
bool hasPickup = pickupLat != 0 && pickupLng != 0;
|
||||
final Completer<GoogleMapController> mapController = Completer();
|
||||
|
||||
double riderLat = 0.0;
|
||||
double riderLng = 0.0;
|
||||
@@ -2661,36 +2661,46 @@ void _showmapDetailsSheet(
|
||||
|
||||
final bool hasAny = hasRiderLocation && hasPickup;
|
||||
|
||||
final List<LatLng> polylineCoords = [];
|
||||
final Set<Polyline> polylines = {};
|
||||
|
||||
const String googleAPIKey = "AIzaSyBhkGfnq27sN0wV5y_S-M2KojpFTk_by-Q";
|
||||
final List<NearleMapPolyline> polylines = [];
|
||||
|
||||
if (hasRiderLocation && hasPickup) {
|
||||
final PolylinePoints polylinePoints = PolylinePoints(apiKey: googleAPIKey);
|
||||
final PolylineResult result = await polylinePoints
|
||||
.getRouteBetweenCoordinates(
|
||||
request: PolylineRequest(
|
||||
origin: PointLatLng(riderLat, riderLng),
|
||||
destination: PointLatLng(pickupLat, pickupLng),
|
||||
mode: TravelMode.driving,
|
||||
),
|
||||
);
|
||||
if (result.points.isNotEmpty) {
|
||||
for (var point in result.points) {
|
||||
polylineCoords.add(LatLng(point.latitude, point.longitude));
|
||||
}
|
||||
final route = await RoutingService.getRoute(
|
||||
origin: LatLng(riderLat, riderLng),
|
||||
destination: LatLng(pickupLat, pickupLng),
|
||||
);
|
||||
if (route != null && route.points.isNotEmpty) {
|
||||
polylines.add(
|
||||
Polyline(
|
||||
polylineId: const PolylineId("route"),
|
||||
NearleMapPolyline(
|
||||
id: 'route',
|
||||
points: route.points,
|
||||
color: Colors.blueAccent,
|
||||
width: 5,
|
||||
points: polylineCoords,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final List<NearleMapMarker> mapMarkers = [];
|
||||
if (hasRiderLocation) {
|
||||
mapMarkers.add(
|
||||
NearleMapMarker(
|
||||
id: 'rider',
|
||||
position: LatLng(riderLat, riderLng),
|
||||
icon: await MapMarkerIcons.dot(Colors.blueAccent),
|
||||
anchor: MarkerAnchor.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (hasPickup) {
|
||||
mapMarkers.add(
|
||||
NearleMapMarker(
|
||||
id: 'pickup',
|
||||
position: LatLng(pickupLat, pickupLng),
|
||||
icon: await MapMarkerIcons.pin(Colors.red),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ⭐ STEP 3 — Close loader
|
||||
Navigator.pop(context);
|
||||
|
||||
@@ -2848,7 +2858,7 @@ void _showmapDetailsSheet(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
),
|
||||
child: GoogleMap(
|
||||
child: NearleMap(
|
||||
initialCameraPosition: CameraPosition(
|
||||
target: hasRiderLocation && hasPickup
|
||||
? LatLng(
|
||||
@@ -2862,52 +2872,22 @@ void _showmapDetailsSheet(
|
||||
: const LatLng(0, 0),
|
||||
zoom: hasRiderLocation && hasPickup ? 13 : 15,
|
||||
),
|
||||
markers: {
|
||||
if (hasRiderLocation)
|
||||
Marker(
|
||||
markerId: const MarkerId("rider"),
|
||||
position: LatLng(riderLat, riderLng),
|
||||
infoWindow: const InfoWindow(
|
||||
title: "Your Location",
|
||||
),
|
||||
icon: BitmapDescriptor.defaultMarkerWithHue(
|
||||
BitmapDescriptor.hueAzure,
|
||||
),
|
||||
),
|
||||
if (hasPickup)
|
||||
Marker(
|
||||
markerId: const MarkerId("pickup"),
|
||||
position: LatLng(pickupLat, pickupLng),
|
||||
infoWindow: const InfoWindow(
|
||||
title: "Pickup Location",
|
||||
),
|
||||
icon: BitmapDescriptor.defaultMarkerWithHue(
|
||||
BitmapDescriptor.hueRed,
|
||||
),
|
||||
),
|
||||
},
|
||||
markers: mapMarkers,
|
||||
polylines: polylines,
|
||||
zoomGesturesEnabled: true,
|
||||
scrollGesturesEnabled: true,
|
||||
tiltGesturesEnabled: true,
|
||||
rotateGesturesEnabled: true,
|
||||
zoomControlsEnabled: false,
|
||||
myLocationButtonEnabled: false,
|
||||
onMapCreated: (GoogleMapController controller) async {
|
||||
mapController.complete(controller);
|
||||
onMapReady: (controller) async {
|
||||
if (hasRiderLocation && hasPickup) {
|
||||
final bounds = LatLngBounds(
|
||||
southwest: LatLng(
|
||||
riderLat < pickupLat ? riderLat : pickupLat,
|
||||
riderLng < pickupLng ? riderLng : pickupLng,
|
||||
await controller.fitBounds(
|
||||
LatLngBounds(
|
||||
southwest: LatLng(
|
||||
riderLat < pickupLat ? riderLat : pickupLat,
|
||||
riderLng < pickupLng ? riderLng : pickupLng,
|
||||
),
|
||||
northeast: LatLng(
|
||||
riderLat > pickupLat ? riderLat : pickupLat,
|
||||
riderLng > pickupLng ? riderLng : pickupLng,
|
||||
),
|
||||
),
|
||||
northeast: LatLng(
|
||||
riderLat > pickupLat ? riderLat : pickupLat,
|
||||
riderLng > pickupLng ? riderLng : pickupLng,
|
||||
),
|
||||
);
|
||||
await controller.animateCamera(
|
||||
CameraUpdate.newLatLngBounds(bounds, 80),
|
||||
padding: 80,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user