getMapPostition returns null value

127 Views Asked by At
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.

1

There are 1 best solutions below

1
trashgod On BEST ANSWER

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);