@@ -247,7 +247,7 @@ class LocationCubit extends Cubit<LocationState> {
247247
248248 emit (LoadedLocationState (
249249 geofence: _geofence,
250- locationMarkers: _hikeMarkers,
250+ locationMarkers: Set < Marker >. from ( _hikeMarkers) ,
251251 polyline: _polyline,
252252 version: DateTime .now ().millisecondsSinceEpoch,
253253 mapType: _mapType,
@@ -260,7 +260,7 @@ class LocationCubit extends Cubit<LocationState> {
260260 PolylinePoints polylinePoints = PolylinePoints ();
261261 try {
262262 PolylineResult result = await polylinePoints.getRouteBetweenCoordinates (
263- 'AIzaSyBdIpiEfBE5DohHgBvwPTljZQAcNWcKwCs ' ,
263+ 'AIzaSyC72TkXzQTsnbGdZy5ldeX64y0mofn_iUs ' ,
264264 PointLatLng (_points.first.latitude, _points.first.longitude),
265265 PointLatLng (_points.last.longitude, _points.last.longitude));
266266
@@ -363,18 +363,29 @@ class LocationCubit extends Cubit<LocationState> {
363363 if (dataState is DataSuccess && dataState.data != null ) {
364364 BeaconLocationsEntity beaconLocationsEntity = dataState.data! ;
365365
366+ print (
367+ 'Location update subscription: ${beaconLocationsEntity .toString ()}' );
368+
369+ // when new landmark is created
366370 // when new landmark is created
367371 if (beaconLocationsEntity.landmark != null ) {
368372 LandMarkEntity newLandMark = beaconLocationsEntity.landmark! ;
369373
370- // await _createLandMarkMarker(newLandMark);
374+ print ('Creating landmark marker for: ${newLandMark .title }' );
375+ print ('Markers before: ${_hikeMarkers .length }' );
376+
377+ await _createLandMarkMarker (newLandMark);
378+
379+ print ('Markers after: ${_hikeMarkers .length }' );
371380
372381 emit (LoadedLocationState (
373382 polyline: _polyline,
374- locationMarkers: _hikeMarkers,
383+ locationMarkers:
384+ Set <Marker >.from (_hikeMarkers), // Create new Set instance
375385 mapType: _mapType,
376386 geofence: _geofence,
377- version: DateTime .now ().millisecond,
387+ version: DateTime .now ()
388+ .millisecondsSinceEpoch, // Use millisecondsSinceEpoch
378389 message:
379390 'A landmark is created by ${beaconLocationsEntity .landmark !.createdBy !.name ?? 'Anonymous' }' ));
380391 }
@@ -388,9 +399,9 @@ class LocationCubit extends Cubit<LocationState> {
388399 emit (LoadedLocationState (
389400 polyline: _polyline,
390401 geofence: _geofence,
391- locationMarkers: _hikeMarkers,
402+ locationMarkers: Set < Marker >. from ( _hikeMarkers) ,
392403 mapType: _mapType,
393- version: DateTime .now ().microsecond ));
404+ version: DateTime .now ().millisecondsSinceEpoch ));
394405 // add marker for user
395406 }
396407
@@ -460,10 +471,10 @@ class LocationCubit extends Cubit<LocationState> {
460471 calculateMapBoundsFromListOfLatLng (_points), 50 ));
461472
462473 emit (LoadedLocationState (
474+ polyline: _polyline,
463475 geofence: _geofence,
464- locationMarkers: _hikeMarkers,
476+ locationMarkers: Set < Marker >. from ( _hikeMarkers) ,
465477 mapType: _mapType,
466- polyline: _polyline,
467478 version: DateTime .now ().millisecondsSinceEpoch));
468479 } else if (beaconLocationsEntity.userSOS != null ) {
469480 var user = beaconLocationsEntity.userSOS! ;
@@ -669,21 +680,25 @@ class LocationCubit extends Cubit<LocationState> {
669680 return _address.isNotEmpty ? _address : null ;
670681 }
671682
672- // update here
673683 Future <void > createLandmark (
674684 String beaconId, String title, LatLng latlng, String icon) async {
675- print ("Creating landmark with title: $title at $latlng " );
676685 var dataState = await _hikeUseCase.createLandMark (beaconId, title,
677686 latlng.latitude.toString (), latlng.longitude.toString (), icon);
678- print ( "Data state: $ dataState " );
687+
679688 if (dataState is DataSuccess && dataState.data != null ) {
680- print ('result Creating marker for landmark: 1 : ${dataState .data ?. icon }' );
689+ print ('Local landmark created : ${dataState .data !. title }' );
681690 await _createLandMarkMarker (dataState.data! );
691+
692+ await locationUpdateSubscription (beaconId);
693+
682694 emit (LoadedLocationState (
683695 polyline: _polyline,
684696 geofence: _geofence,
685697 mapType: _mapType,
686- locationMarkers: Set <Marker >.from (_hikeMarkers),
698+ locationMarkers:
699+ Set <Marker >.from (_hikeMarkers), // Create new Set instance
700+ version:
701+ DateTime .now ().millisecondsSinceEpoch, // Consistent versioning
687702 message: 'New marker created by ${dataState .data !.createdBy !.name }' ));
688703 }
689704 }
@@ -733,7 +748,7 @@ class LocationCubit extends Cubit<LocationState> {
733748 _hikeMarkers.where ((element) => element.markerId == markerId);
734749
735750 if (existingMarkers.isEmpty) {
736- var newMarker = await createMarkerWithCircularNetworkImage (
751+ var newMarker = await createMarkerWithLocalAsset (
737752 landMark,
738753 );
739754 _hikeMarkers.add (newMarker);
@@ -785,11 +800,44 @@ class LocationCubit extends Cubit<LocationState> {
785800 }
786801 }
787802
803+ Future <Marker > createMarkerWithLocalAsset (LandMarkEntity landmark) async {
804+ Future <BitmapDescriptor > getResizedMarkerIcon (
805+ String assetPath, int width) async {
806+ final ByteData data = await rootBundle.load (assetPath);
807+ final codec = await ui.instantiateImageCodec (
808+ data.buffer.asUint8List (),
809+ targetWidth: width,
810+ );
811+ final frame = await codec.getNextFrame ();
812+ final ui.Image image = frame.image;
813+
814+ final byteData = await image.toByteData (format: ui.ImageByteFormat .png);
815+ final Uint8List resizedBytes = byteData! .buffer.asUint8List ();
816+
817+ return BitmapDescriptor .fromBytes (resizedBytes);
818+ }
819+
820+ BitmapDescriptor customIcon = await getResizedMarkerIcon (
821+ landmark.icon ?? 'images/icons/location-marker.png' ,
822+ 80 , // desired width in pixels
823+ );
824+
825+ return Marker (
826+ markerId: MarkerId (landmark.id! .toString ()),
827+ position: locationToLatLng (landmark.location! ),
828+ icon: customIcon,
829+ infoWindow: InfoWindow (
830+ title:
831+ '${landmark .title } by ${landmark .createdBy ?.name ?? 'Anonymous' }' ,
832+ ),
833+ );
834+ }
835+
788836 Future <Marker > createMarkerWithCircularNetworkImage (
789837 LandMarkEntity landmark) async {
790838 print ("Creating marker for landmark: ${landmark .createdBy ?.imageUrl }" );
791839 final Uint8List markerIcon = await getCircularImageWithBorderAndPointer (
792- landmark.icon ?? 'assets /icons/location-marker.png' ,
840+ landmark.icon ?? 'images /icons/location-marker.png' ,
793841 size: 80 ,
794842 borderColor: Colors .teal,
795843 borderWidth: 4 ,
0 commit comments