问题
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.
回答1:
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!)
回答2:
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+ .
回答3:
import org.osmdroid.api.IMapController;
private IMapController myMapController;
来源:https://stackoverflow.com/questions/36742161/osmdroid-error-incompatible-types-igeopoint-cannot-be-converted-to-geopoint