OSMDROID: error: incompatible types: IGeoPoint cannot be converted to GeoPoint
Asked Answered
B

3

1

I am building a sample OSMdroid app mixing and matching from various sources.

In using this sample code,

import org.osmdroid.util.GeoPoint;
...
 private void setOverlayLoc(Location overlayloc){
   GeoPoint overlocGeoPoint = new GeoPoint(overlayloc);
  //---
     overlayItemArray.clear();

     OverlayItem newMyLocationItem = new OverlayItem(
       "My Location", "My Location", overlocGeoPoint);
     overlayItemArray.add(newMyLocationItem);
  }
...
   @Override
   public void draw(Canvas canvas, MapView mapview, boolean arg2) {
...
     //overlayItemArray have only ONE element only, so I hard code to get(0)
     GeoPoint in = overlayItemArray.get(0).getPoint();

I started receiving the following error (in reference to the last line above):

error: incompatible types: IGeoPoint cannot be converted to GeoPoint

I am using Android Studio 2.0, osmdroid 4.3, slf4j 1.6.1

The error message makes very little sense to me, since i did not declare or import said IGeoPoint class. Any suggestions as to how to go about this would be greatly appreciated.

Blackmarket answered 20/4, 2016 at 11:18 Comment(0)
N
3

OverlayItem.getPoint() returns a IGeoPoint, and Projection.toPixels() needs a IGeoPoint. So :

IGeoPoint in = overlayItemArray.get(0).getPoint();

mapview.getProjection().toPixels(in, out);

(and don't go back to an older version, but upgrade to the latest one!)

Nashom answered 20/4, 2016 at 21:3 Comment(1)
wasnt explicitely dealing with projections. lemme check this angle. UPVOTED! :)Blackmarket
B
1

Workaround: Change the osmdroid version from 4.3 to 3.0.x. IGeoPoint class does not exist in 3.0.x, but in 4.3 it does.

NOTE: version 4.2 has the same problem with IMapController

Solution: Change declaration to private IGeoPoint startPoint; and the same for IMapController and my code became compatible with versions 4.3+ .

Blackmarket answered 20/4, 2016 at 11:33 Comment(0)
D
-2
import org.osmdroid.api.IMapController;


private IMapController myMapController;
Drawers answered 18/1, 2018 at 23:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.