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

coordinateForPoint inaccurate for Android. #2395

Closed
jamiesonbates opened this issue Jul 24, 2018 · 5 comments
Closed

coordinateForPoint inaccurate for Android. #2395

jamiesonbates opened this issue Jul 24, 2018 · 5 comments

Comments

@jamiesonbates
Copy link

Is this a bug report?

Yes.

Have you read the Installation Instructions?

Yes.

Environment

react-native: 0.55.3
react: 16.3.1
react-native-maps: "git+https://github.com/react-community/react-native-maps.git"

Steps to Reproduce

  1. Navigate to a view with a map on it.
  2. Make sure you are in a mode that allows you to draw on the map by pressing and holding your finger on your device.
  3. Press and hold, while drawing a circle or other shape.
  4. Release.

Expected Behavior

The circle generated should generate a list of x/y points in relation to the screen, and then run each through the function coordinateForPoint attached to the map ref. These points will then generate a polyline that resemble exactly where on the map the circle was drawn with your finger.

Then, the coordinateForPoint function should reliable cast a Point as a Coordinate.

Actual Behavior

On android only, this does not work. Instead, the polyline is cast on a different part of the screen (lower and to the right). I think this is a bug with coordinateForPoint because it should be comparing reliably to the mapview visible on the screen, but seems to be casting on a larger view (off-screen).

Unfortunately, I cannot give screenshots, but I created an expo example.

Reproducible Demo

I have built a working example to explain how it is supposed to work. However, I don't think expo has the most recent react-native-maps version and "coordinateForPoint" does not seem to exist when testing on Android.

When testing on IOS it displays what should (mostly) happen. The circle is a polyline drawn from coordinates generated through coordinateForPoint (I am not sure why the red line connects all of them, but its irrelevant for arguments sake).

https://snack.expo.io/@jamiesonbates/react-native-maps-coordinateforpoint-example

@danielgindi
Copy link
Contributor

There's already a PR for that (#2390)
A temporary workaround:

    let position = await this._refs.map.pointForCoordinate(coordinate);
    if (Platform.OS === 'android') { // FIXME: Remove this in next module version
      position.x = position.x / PixelRatio.get();
      position.y = position.y / PixelRatio.get();
    }

@jamiesonbates
Copy link
Author

@danielgindi thank you so much for the work around. Saved me a ton of time. Looking forward to the PR.

Appreciate your contribution to this library as well.

@jamiesonbates
Copy link
Author

jamiesonbates commented Jul 25, 2018

Duplicate of #2390

@cklinx
Copy link

cklinx commented Nov 11, 2018

There's already a PR for that (#2390)
A temporary workaround:

    let position = await this._refs.map.pointForCoordinate(coordinate);
    if (Platform.OS === 'android') { // FIXME: Remove this in next module version
      position.x = position.x / PixelRatio.get();
      position.y = position.y / PixelRatio.get();
    }

@danielgindi Thanks man, you saved my life!

@danielgindi
Copy link
Contributor

@cklinx This is actually old, and the "next" module version is here. If you upgrade, you do not need this workaround :-)

This issue was closed.
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

3 participants