OSMDROID: error: incompatible types: IGeoPoint cannot be converted to GeoPoint

我只是一个虾纸丫 提交于 2020-02-29 04:56:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!