2
Point da = map1().getMapPosition(48.922499263758255, 16.875);
System.out.println(da);

Can someone help me? I want to convert a coordinate to a point by using this getMapPosition, but whatever I do it gives me a null value. Why is it happening?

Thanks.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Renrenren
  • 25
  • 5

1 Answers1

1

A quick check of the relevant JMapViewer source shows that your call to getMapPosition() invokes a nearby overload with checkOutside set to true. The result is null if the Point corresponding to the coordinates is outside the visible map.

if (checkOutside && (p.x < 0 || p.y < 0 || p.x > getWidth() || p.y > getHeight())) {
    return null;
}

Instead, use one of the implementations that lets you set checkOutside to false explicitly. For example,

Point da = map1().getMapPosition(48.9225, 16.875, false);

or

Coordinate coord = new Coordinate(48.9225, 16.875);
Point da = map1().getMapPosition(coord, false);
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    Thanks a lot sir for your reply, I figured out where I am wrong, I just needed to create a variable Coordinate coord then add the false Point da = map1().getMapPosition(coord, false); then it gives me now the correct Point values tnx a lot :) – Renrenren Apr 19 '17 at 04:15