Reputation: 1
This is with the magic numbers This is without magic numbers I am trying to add raw magnifier widget on the google map marker which activates when marker is dragged, i cannot wrap the marker as it is not a flutter widget i tried passing cordinates to the widget using google controller screen cordinates they worked but they are not accurate and varries from device to device , then i tried gesture detector but after using it dosent allow me to navigate on map or drag the marker also tried hit behviour translucent , next i tries listener but it is also not accurate and dosent work while dragging is THERE ANY OTHER WAY WHICH MIGHT WORK?
Future<void> _handleDrag(LatLng newPosition) async {
_lastMarkerPosition = newPosition;
GoogleMapController controller = await _controller.future;
ScreenCoordinate screenCoordinate =
await controller.getScreenCoordinate(newPosition);
print(
'Screen coordinates: x=${screenCoordinate.x}, y=${screenCoordinate.y}');
// Update state with new screen coordinates
setState(() {
_left = screenCoordinate.x.toDouble() / 1.9 - 60;
_top = screenCoordinate.y.toDouble() / 1.9 - 45;
});
}
`
: Stack(children: [
GoogleMap(
mapType: MapType.hybrid,
initialCameraPosition: gblFactoryLocation,
compassEnabled: false,
myLocationButtonEnabled: true,
myLocationEnabled: true,
polylines: _polyline,
// If empty, returns error
//CODE//
onTap: (position) {
if (isAddingPlot) {
int index_element = 0;
setState(() {
Marker newMarker = Marker(
markerId: MarkerId(position.toString()),
position: position,
draggable: true,
onDrag: _handleDrag,
// rotation: 180,
icon: BitmapDescriptor.defaultMarkerWithHue(
BitmapDescriptor.hueCyan),
consumeTapEvents: false,
onDragStart: (oldPosition) {
isMagnifierVisible = true;
// Finding nearest marker (Since its not accurate)
double distance = calculateDistance(
oldPosition.latitude,
oldPosition.longitude,
new_polygon.points[0].latitude,
new_polygon.points[0].longitude);
for (var i = 0;
i < new_polygon.points.length;
i++) {
double dist = calculateDistance(
oldPosition.latitude,
oldPosition.longitude,
new_polygon.points[i].latitude,
new_polygon.points[i].longitude);
if (dist < distance) {
index_element = i;
distance = dist;
}
}
},
onDragEnd: (position) {
isMagnifierVisible = false;
new_polygon.points.removeAt(index_element);
new_polygon.points.insert(
index_element,
LatLng(
position.latitude, position.longitude));
// CODE//
Positioned(
left: _left,
top: _top,
child: isMagnifierVisible
? const RawMagnifier(
decoration: MagnifierDecoration(
shape: CircleBorder(
side: BorderSide(color: Colors.pink, width: 3),
),
),
size: Size(140, 140),
magnificationScale: 2,
)
: SizedBox.shrink(),
),`
Upvotes: 0
Views: 76