Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show Marker (convert pixel to latitude and longitude) based on X Y pixel on fixed size map? #981

Closed
DVCStudioX opened this issue Aug 1, 2021 · 3 comments

Comments

@DVCStudioX
Copy link

I have a map size 1024x1024, and a point in the position x 671, y 560

alt text

So what formula to get latitude and longitude of that point to show the Marker?

Pls help me, this is the full code:

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';

void main() => runApp(MaterialApp(home: HomePage()));

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var imgHeight = 1024;
    var imgWidth = 1024;

    var pointY = 560;
    var pointX = 671;

    var markers = <Marker>[
      Marker(
        point: LatLng(0, 0), // How to get position of XY
        builder: (ctx) => Container(child: Icon(Icons.clear)),
      ),
    ];

    return Scaffold(
      appBar: AppBar(title: Text('Home')),
      body: FlutterMap(
        options: MapOptions(
          interactiveFlags: InteractiveFlag.all & ~InteractiveFlag.rotate,
          center: LatLng(0, 0),
          zoom: 0,
        ),
        layers: [
          TileLayerOptions(
            urlTemplate:
                'https://firebasestorage.googleapis.com/v0/b/tft-test-48c87.appspot.com/o/LatLng%2F{z}%2F{y}%2F{x}.png?alt=media&token=c5eb1e3f-4240-4128-b0e2-5bd4936d9447',
            tileProvider: NonCachingNetworkTileProvider(),
          ),
          MarkerLayerOptions(markers: markers)
        ],
      ),
    );
  }
}


@JaffaKetchup
Copy link
Member

JaffaKetchup commented Aug 1, 2021

You can use a version of a formula available at https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames, but try using the built in CRS methods. Specifically you'll need pointToLatLng() (I think it's called that), and potentially (un)scaleBy().

You may want to check out this comment and the surrounding thread: #941 (comment)

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Sep 26, 2021
@github-actions
Copy link

github-actions bot commented Oct 1, 2021

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as completed Oct 1, 2021
JaffaKetchup pushed a commit that referenced this issue May 20, 2022
…nt (#1115)

* Added MapController.pointToLatLng() to get LatLng of given screen point

Ref #496, ref #607, ref #981, ref #1010

* Better pointToLatLng example

* dartfmt

* Fix zoom breaking pointToLatLng()

* Updated example to help fix the rotation issue

* Rebased on latest

* Fix pointToLatLng with rotation

* Fix trailing lines (3x attempts)

Co-authored-by: Polo <[email protected]> and ibrierley
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants