0
我需要一點幫助。我使用「org.mapsforge.android.maps」編寫了一個android應用程序。 那裏我創建了一個自定義覆蓋,我想在地圖中顯示。地圖顯示,但沒有覆蓋。我看到「mapView.getOverlays().add(myOverlay)」將myOverlay添加到mapView,但屏幕上沒有任何反應。 有人有一個想法,爲什麼不呢?android mapsforge覆蓋不顯示在視圖
非常感謝
湯姆
@Override
public void onCreate(Bundle savedInstanceState) {
try
{
res= this.getResources();
context=this;
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.openstreet);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.main_title_back);
// get the pointers to different system services
this.locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
this.myLocationListener = new MyLocationListener(this);
if(getIntent().hasExtra("comingfrom") == true)
comingfrom = getIntent().getExtras().getString("comingfrom");
if(getIntent().hasExtra("latitude") == true)
mlatitude = getIntent().getExtras().getDouble("latitude");
if(getIntent().hasExtra("longitude") == true)
mlongitude = getIntent().getExtras().getDouble("longitude");
initMapView();
Log.i(Properties.getProgramname(), "OpenStreetActivity->onCreate: Übergebene Koordinate Lat=" + mlatitude + " Lon=" + mlongitude);
if (comingfrom.equals("ButtonArea"))
{
LoadData();
}
else
{
}
if (this.locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
initMyLocation(true);
} else {
Toast.makeText(this,"GPS Provider not enabled",Toast.LENGTH_LONG).show();
}
// create a GeoPoint with the latitude and longitude coordinates
GeoPoint geoPoint = new GeoPoint(mlatitude, mlongitude);
mapController.setCenter(geoPoint);
mapController.setZoom(16);
}
catch (Exception ex)
{
Log.e(Properties.getProgramname(), "Fehler in OpenStreetActivity->onCreate: " + ex.getLocalizedMessage());
Toast.makeText(this,"UI problem " + ex.getMessage(),Toast.LENGTH_LONG).show();
}
}
/**
* Initialize the OSM
*
*/
private void initMapView()
{
settingsLayer = new TJHookerSettingsLayer(this);
Cursor cur = settingsLayer.ladeSettings();
String filename =cur.getString(cur.getColumnIndex(TJHookerSettingsTables.MAPFILE));
cur.close();
mapView = (MapView) this.findViewById(R.id.openmapview);
this.mapView.setClickable(true);
this.mapView.setBuiltInZoomControls(true);
this.mapView.setFocusable(true);
if (!this.mapView.getMapGenerator().requiresInternetConnection()) {
File file = new File(filename);
if (file.exists())
mapView.setMapFile(new File(filename));
else
Toast.makeText(this,"Problem: Mapfile not found. Please correct the path of your mapfile",Toast.LENGTH_LONG).show();
}
mapController = this.mapView.getController();
}
/**
* Show the current location of my position
*
*/
private void initMyLocation(boolean centerAtFirstFix)
{
try
{
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String bestProvider = this.locationManager.getBestProvider(criteria, true);
this.itemizedMyLocationOverlay = new ArrayItemizedOverlay(null);
this.overlayMyLocationItem = new OverlayItem();
this.overlayMyLocationItem.setMarker(ItemizedOverlay.boundCenter(getResources().getDrawable(R.drawable.my_location)));
this.itemizedMyLocationOverlay.addItem(this.overlayMyLocationItem);
this.mapView.getOverlays().add(this.itemizedMyLocationOverlay);
this.myLocationListener.setCenterAtFirstFix(centerAtFirstFix);
this.locationManager.requestLocationUpdates(bestProvider, 1000, 0, this.myLocationListener);
}
catch(Exception ex)
{
Log.e(Properties.getProgramname(), "Fehler in OpenStreetActivity->initMyLocation: " + ex.getLocalizedMessage());
Toast.makeText(OpenStreetActivity.this, "!initMyLocation: " + ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
// neuen Thread starten
private void LoadData()
{
if(mlongitude > 0 && mlatitude > 0)
{
SystemInformation sys = new SystemInformation();
if(sys.isNetworkAvailable(this))
{
// Neuen Thread startenn der die Kontakte laden soll. Activity wir schon angezeigt
prog = ProgressDialog.show(this, res.getString(R.string.gc40_progtitle), "", true, false);
prog.setMessage(Html.fromHtml("<font color='white'>" + res.getString(R.string.gc40_progtext) + "</font>"));
pdIsShow=true;
Thread thread = new Thread(this);
thread.start();
}
}
}
@Override
public void run() {
GCApiRequests _apiRequests= new GCApiRequests();
try {
lc = _apiRequests.GetCacheByArea(Properties.getGCAccessToken(), mlongitude, mlatitude,"5000", GeocachingConstants.maxCachesPerPage);
handler.sendEmptyMessage(0);
} catch (Exception e) {
Log.e(Properties.getProgramname(), "KartenAnzeigenActivity->Fehler in run: " + e.getLocalizedMessage());
handler.sendEmptyMessage(1);
}
}
// Wenn Thread alle Kontakte geladen hat, dann in ListView anzeigen
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (pdIsShow)
prog.dismiss();
setOverlayCaches();
}
};
private void setOverlayCaches()
{
try {
CacheType typ = new CacheType();
lc.trimToSize();
Log.i(Properties.getProgramname(), "OpenStreetActivity->setOverlayCache: Anzahlgefundener Caches=" +lc.size());
/** So, jetzt gehen wir erstmal durch alle Logs von geocaching.com durch */
// create an ItemizedOverlay with the default marker
CacheOpenStreetMapItemizedOverlay myOverlay= new CacheOpenStreetMapItemizedOverlay(getResources().getDrawable(typ.getCacheType(2)), context);
for(Geocache cache: lc)
{
// create a GeoPoint with the latitude and longitude coordinates
int lat = (int) (Double.parseDouble(cache.GetLatitude()) * 1e6);
int lon = (int) (Double.parseDouble(cache.GetLongitude()) * 1e6);
GeoPoint geoPoint = new GeoPoint(lat,lon);
// create an OverlayItem with title and description
OverlayItem item = new OverlayItem(geoPoint, cache.GetCacheName(), cache.GetGCCode(),
getResources().getDrawable(typ.getCacheType(Integer.parseInt(cache.GetCacheType()))));
myOverlay.addOverlay(item);
}
myOverlay.requestRedraw();
// add the ArrayItemizedOverlay to the MapView
//if (traditionellOverlay != null)
Log.i(Properties.getProgramname(), "OpenStreetActivity->setOverlayCache: Anzahl Overlay items=" + myOverlay.size());
Log.i(Properties.getProgramname(), "OpenStreetActivity->setOverlayCache: Anzahl MapView Overlays=" + mapView.getOverlays().size());
mapView.getOverlays().add(myOverlay);
Log.i(Properties.getProgramname(), "OpenStreetActivity->setOverlayCache: Anzahl MapView Overlays=" + mapView.getOverlays().size());
} catch (Exception e) {
Log.e(Properties.getProgramname(), "KartenAnzeigenActivity->Fehler in setOverlayCaches: " + e.getLocalizedMessage());
}
}
/** Back-Button in Titlebar wurde gedrückt */
public void PressTitleBackButton_Click(View view)
{
/** Durch ein finish() wird der Back-Button Effekt ausgelöst. */
finish();
}