ResponsiveFramework icon indicating copy to clipboard operation
ResponsiveFramework copied to clipboard

Marker are not at correct position when responsive_framework is used with flutter_map

Open pmg1991 opened this issue 3 years ago • 3 comments

I have the same issue.

class MapsBaseWidget extends StatefulWidget {
  const MapsBaseWidget({
    Key? key,
  }) : super(key: key);

  @override
  State<MapsBaseWidget> createState() => _MapsBaseWidgetState();
}

class _MapsBaseWidgetState extends State<MapsBaseWidget> {
  final List<Marker> markers = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FlutterMap(
        options: MapOptions(
            center: LatLng(51.5, 9.05),
            zoom: 13.0,
            onLongPress: (_, LatLng latLng) {
              setState(() {
                markers.add(Marker(
                  width: 80.0,
                  height: 80.0,
                  point: latLng,
                  builder: (ctx) => const Icon(Icons.location_on),
                ));
              });
            }),
        layers: [
          TileLayerOptions(
            urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
            subdomains: ['a', 'b', 'c'],
            attributionBuilder: (_) {
              return Text("© OpenStreetMap contributors");
            },
          ),
          MarkerLayerOptions(
            markers: markers,
          ),
        ],
      ),
    );
  }
}

here is an image with tap position and marker on wrong place. Fresh card not rotated or zoomed

image

Originally posted by @tk2232 in https://github.com/fleaflet/flutter_map/issues/1091#issuecomment-1023520245

pmg1991 avatar Mar 17 '22 06:03 pmg1991

@pmg1991 I solved the problem as follows https://github.com/Codelessly/ResponsiveFramework/issues/50#issuecomment-1023641178

tk2232 avatar Mar 17 '22 08:03 tk2232

@tk2232 After your suggested changes nonrotated child are getting out of screen. iPhone-8-Plus-7-Plus-6S-Plus-414x736

pmg1991 avatar Mar 17 '22 10:03 pmg1991

The same here problem is with the buttons above the map not being clickable on release builds only on some phones like Redmi 8A.

https://github.com/Codelessly/ResponsiveFramework/issues/50#issuecomment-1023641178 This solution solves it partially.

Thanks

ElKood-Sol avatar Sep 14 '22 13:09 ElKood-Sol

If you are using responsive_framework and getting wrong marker position with flutter_map

Here is the solution to get accurate position.

FlutterMap Controller has a method pointToLatLng I used that method to convert point where user tapped to latlng.

Here is my solution

Inside onTap method of FlutterMap MapOptions we get LatLng and TapPosition

I used TapPosition object

             var rescalingFactor =
                            (ResponsiveWrapper.of(context).scaledHeight /
                                ResponsiveWrapper.of(context).screenHeight);

Use this rescalingFactor to create accurate LatLng

             var ltlng = mapController.pointToLatLng(CustomPoint(
                            tapPosition.relative!.dx * rescalingFactor,
                            tapPosition.relative!.dy * rescalingFactor));                        

Now this will land your pin at right position.

ch-muhammad-adil avatar Oct 06 '22 08:10 ch-muhammad-adil

Instead of rescaling flutter map I have actually repositioned where user has actually tapped and this returns accurate LatLng.

PS: if you use resizing instead of autoScale in your ResposiveFramework Wrapper you won't see any problem with flutter_map tap. But if you are seeing a problem for particular screen width or configuration of ResponsiveFramework, you can just apply my solution.

ch-muhammad-adil avatar Oct 06 '22 08:10 ch-muhammad-adil

Instead of rescaling flutter map I have actually repositioned where user has actually tapped and this returns accurate LatLng.

PS: if you use resizing instead of autoScale in your ResposiveFramework Wrapper you won't see any problem with flutter_map tap. But if you are seeing a problem for particular screen width or configuration of ResponsiveFramework, you can just apply my solution.

ch-muhammad-adil avatar Oct 06 '22 08:10 ch-muhammad-adil

@rayliverified we may need to reopen this now with 1.1.0.

mdmm13 avatar Aug 08 '23 08:08 mdmm13

@tk2232 @pmg1991 were you able to solve this with 1.1.0? We're stuck, because of scaledWidth missing #145.

mdmm13 avatar Aug 08 '23 08:08 mdmm13