Goddchen
Goddchen

Reputation: 4458

osmdroid coordinate conversion for markers

I'm facing a coordinate system problem with osmdroid and the recently released GuildWars 2 Map API.

That API returns POIs that I want to add to the map (which display just fine, yeay :)).

One example is:

{"poi_id":1486,"name":"Falooaloo","type":"landmark","floor":1,"coord":[19760.9,15379.5]}

So, I have coordinates in absolute XY in relation to the whole map's XY size.

But how to convert that to a GeoPoint that I can use for a marker location?

When I use TileSystem.PixelXYToLatLong(...) I'm always getting the same result: -84928320, 178593750,0. Which is the bottom right of the world.

I don't see what I'm doing wrong. Any ideas?

Goddchen

Upvotes: 1

Views: 1434

Answers (1)

kurtzmarc
kurtzmarc

Reputation: 3137

It all depends on how those x,y coordinates are meant to be interpreted. A few suggestions:

  1. Try using the map's projection class to convert from pixels to a Geopoint.

    IGeoPoint p = mMapView.getProjection().fromPixels(...);
    
  2. What zoom level are the coordinates expected to be in? If you don't specify a zoom level to the API, then you will need to adjust this accordingly.

  3. Finally, note that osmdroid uses the center of the map as the origin and not the upper-left of the map. So you may need to offset your coordinates by half the world size. To offset them do:

    final int worldsize_2 = TileSystem.MapSize(zoomlevel) / 2;
    final adjustedX = x - worldsize_2;
    final adjustedY = y - worldsize_2;
    

Upvotes: 3

Related Questions