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

Marker Positioning Logic #34

Closed
brenton-crowley opened this issue Oct 4, 2013 · 5 comments
Closed

Marker Positioning Logic #34

brenton-crowley opened this issue Oct 4, 2013 · 5 comments

Comments

@brenton-crowley
Copy link

Hello moagrius,

First of all great work on building something like this from scratch. I've been working on something similar in iOS that renders markers to a static map that has geolocation and user tracking abilities.

I have, however, encountered what appears to be some error in logic in regards to the placement of markers. At first I thought that it must have been my own custom implementation, but upon starting a fresh project from the demo, it appears that the markers do not correlate to their real world positions.

tile-view-bug

As you can see from the attached image, I have just rendered one marker on the Boston map, but when I input the same coordinates into Google Maps, the marker renders in a different position to that in Google Maps.

Am I missing something here, or is this a known issue?

Also, I found the comments in the documentation regarding the parameters in the defineRelativeBounds() method in tileView to be confusing, as the supplied arguments do not match what is defined in the comments.

Shouldn't it be NW (latitude, longitude), SE (latitude, longitude)?

The documentation reads (SE longitude, NW latitude), (NW longitude, SE latitude)

NW = north west
SE = south east

I look forward to your feedback :)

@moagrius
Copy link
Owner

moagrius commented Oct 4, 2013

Hey @brenton-crowley,

As regards the documentation of the signature of define bounds, the signature is defineRelativeBounds(double left, double top, double right, double bottom), which calls PositionManager's public void setBounds( double l, double t, double r, double b ) - my "eg" in the documentation is incorrect - I'll remove next time.

As far as positioning, it's actually pretty basic, and not at all based on geolocation. It just uses a relative point. If you define bounds between 0 and 1, then use a positioning method and pass a value of 0.4, the pixel returned would be 40% of the total axis (width or height, depending on if the 0.4 was for X or Y). So if you define the bounds with latitudes of 45.1250 through 45.6725, it would calculate that 45.39875 would be the vertical halfway point. I suspect that true geolocation wouldn't be as simple, and that the curve of the planet's surface would need to considered, but I think only rarely would this have a visible effect.

The class that does the position translation is PositionManager, and the signature is translate - here's what's actually happening.

The demo is kind of cobbled together from a (very) old version of this widget (2 years?) that did use Boston coordinates, but I could very well have changed them for debugging purposes, or tweaked the corner coordinates, etc. As I said, the positioning methods just take the relative point you supply and multiply that against the dimensions you supply to come back with a pixel position - there's no actual geolocation happening. The original widget did use lat/lng, and the basic relative positioning approach used by TileView, and it was at least close enough so that the markers did line up visually.

I suppose it's possible there's some bad math laying around in there - now that you understand what's happening with positioning, feel free to post back if you discover a problem.

HTH, and thanks for the input.

Mike

@brenton-crowley
Copy link
Author

Hi @moagrius,

I looked a little more beneath the hood and it turns out we are using the same positioning logic (relating to the iOS version I created).

I have identified the problem, and having identified it, the existing documentation now makes much more sense.

The relative position logic translates to x, y positions. This is fine in normal circumstances, but in relation to coordinates things get a little more funky. The conventional way to refer to coordinates is the form:

coordinate(latitude, longitude);

but in a screen environment latitude values correspond to y-values and longitude to x-values. If I were to follow the original documentation and define my bounds as such:

defineRelativeBounds(long, lat, long, lat);

then wherever I add a marker it must also follow this same convention.

addMarker(longitude, latitude);

In the examples provided, the inputted are around the wrong way (lat, long). I will continue with your existing implementation, but perhaps you could update the demo and docs to notify the developer that coordinates should be in the form of (long, lat).

Or perhaps a convenience method could be inserted for adding a marker at a coordinate, and then the tileView can take care of switching the values around. Ultimately, it should reflect the same pattern as the defineRelativeBounds().

tileView.addMarkerAtCoordinate(view, lat, long);

I hope that I made some sense :)

@moagrius
Copy link
Owner

moagrius commented Oct 4, 2013

I had hoped to remove all notion of convention when switching from "faux-geolocation" to "relative positioning", and not making any mention of lat/lng, but I agree that you're right, what few references remain are more confusing and should be removed from the documentation. I'll leave this issue open until I get a chance to do that.

@brenton-crowley
Copy link
Author

Great. Thanks for the clarification.

@moagrius
Copy link
Owner

docs have been updated to remove inconsistent references. thanks for contributing. closing issue now.

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