Drawable drawable = getResources().getDrawable(R.drawable.current_position);
drawable = Marker.boundCenter(drawable);
this.myLocationOverlay = new MyLocationOverlay(this, this.mapView, drawable);
But this code seems not to be good in maps forge 0.4.0
How can i use MyLocationOverlay in mapsforge 0.4.0?
protected ArrayList<MapViewPosition> mapViewPositions = new ArrayList<MapViewPosition>();
protected ArrayList<LayerManager> layerManagers = new ArrayList<LayerManager>();
private MyLocationOverlay myLocationOverlay;
and this inside the onCreate
// a marker to show at the position
Drawable drawable = getResources().getDrawable(R.drawable.current_position);
Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
// create the overlay and tell it to follow the location
this.myLocationOverlay = new MyLocationOverlay(this, this.mapViewPositions.get(0), bitmap);
this.myLocationOverlay.setSnapToLocationEnabled(true);
this.layerManagers.get(0).getLayers().add(this.myLocationOverlay);
this.myLocationOverlay.enableMyLocation(true);
But if i try to run the app, i get a RunTimeException error.
What is wrong with the code?
public class MainActivity extends Activity {
protected ArrayList<MapViewPosition> mapViewPositions = new ArrayList<MapViewPosition>();
protected ArrayList<LayerManager> layerManagers = new ArrayList<LayerManager>();
protected ArrayList<MapView> mapViews = new ArrayList<MapView>();
private MyLocationOverlay myLocationOverlay;
private static final String MAPFILE = "berlin.map";
ImageButton zoomIn;
ImageButton zoomOut;
private MapView mapView;
private TileCache tileCache;
private TileRendererLayer tileRendererLayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidGraphicFactory.createInstance(this.getApplication());
setContentView(R.layout.activity_main);
this.mapView = (MapView) findViewById(R.id.mapView);
this.mapView.setClickable(true);
this.mapView.getMapScaleBar().setVisible(true);
this.mapView.setBuiltInZoomControls(false);
this.mapView.getMapZoomControls().setZoomLevelMin((byte) 10);
this.mapView.getMapZoomControls().setZoomLevelMax((byte) 20);
// create a tile cache of suitable size
this.tileCache = AndroidUtil.createTileCache(this, "mapcache",
mapView.getModel().displayModel.getTileSize(), 1f,
this.mapView.getModel().frameBufferModel.getOverdrawFactor());
// a marker to show at the position
Drawable drawable = getResources().getDrawable(R.drawable.current_position);
Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
// create the overlay and tell it to follow the location
this.myLocationOverlay = new MyLocationOverlay(this, this.mapViewPositions.get(0), bitmap);
this.myLocationOverlay.setSnapToLocationEnabled(true);
this.layerManagers.get(0).getLayers().add(this.myLocationOverlay);
this.myLocationOverlay.enableMyLocation(true);
zoomIn = (ImageButton) findViewById(R.id.zoomIn);
zoomIn.setBackgroundResource(R.drawable.action_click_zoom_in);
zoomOut = (ImageButton) findViewById(R.id.zoomOut);
zoomOut.setBackgroundResource(R.drawable.action_click_zoom_out);
zoomIn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mapView.getModel().mapViewPosition.zoomIn();
}
});
zoomOut.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mapView.getModel().mapViewPosition.zoomOut();
}
});
}
@Override
protected void onStart() {
super.onStart();
this.mapView.getModel().mapViewPosition.setCenter(new LatLong(52.517037, 13.38886));
this.mapView.getModel().mapViewPosition.setZoomLevel((byte) 12);
// tile renderer layer using internal render theme
this.tileRendererLayer = new TileRendererLayer(tileCache,
this.mapView.getModel().mapViewPosition, false, AndroidGraphicFactory.INSTANCE);
tileRendererLayer.setMapFile(getMapFile());
tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.OSMARENDER);
// only once a layer is associated with a mapView the rendering starts
this.mapView.getLayerManager().getLayers().add(tileRendererLayer);
}
@Override
protected void onStop() {
super.onStop();
this.mapView.getLayerManager().getLayers().remove(this.tileRendererLayer);
this.tileRendererLayer.onDestroy();
}
@Override
protected void onDestroy() {
super.onDestroy();
this.tileCache.destroy();
}
private File getMapFile() {
File file = new File(Environment.getExternalStorageDirectory(), MAPFILE);
return file;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
this.mapView.getLayerManager().getLayers().add(tileRendererLayer);
// create the overlay and tell it to follow the location
this.myLocationOverlay = new MyLocationOverlay(this, this.mapViewPositions.get(0), bitmap);
this.myLocationOverlay.setSnapToLocationEnabled(true);
this.mapView.getLayerManager().getLayers().add(this.myLocationOverlay);
this.myLocationOverlay.enableMyLocation(true);
But now i get the error IllegalArgumentException:layer must not be null
this is the stack
06-09 14:53:11.684: E/AndroidRuntime(5904): FATAL EXCEPTION: main
06-09 14:53:11.684: E/AndroidRuntime(5904): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapsforgerescueprova/com.example.mapsforgerescueprova.MainActivity}: java.lang.IllegalArgumentException: layer must not be null
06-09 14:53:11.684: E/AndroidRuntime(5904): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
06-09 14:53:11.684: E/AndroidRuntime(5904): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
06-09 14:53:11.684: E/AndroidRuntime(5904): at android.app.ActivityThread.access$700(ActivityThread.java:150)
06-09 14:53:11.684: E/AndroidRuntime(5904): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
06-09 14:53:11.684: E/AndroidRuntime(5904): at android.os.Handler.dispatchMessage(Handler.java:99)
06-09 14:53:11.684: E/AndroidRuntime(5904): at android.os.Looper.loop(Looper.java:137)
06-09 14:53:11.684: E/AndroidRuntime(5904): at android.app.ActivityThread.main(ActivityThread.java:5283)
06-09 14:53:11.684: E/AndroidRuntime(5904): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 14:53:11.684: E/AndroidRuntime(5904): at java.lang.reflect.Method.invoke(Method.java:511)
06-09 14:53:11.684: E/AndroidRuntime(5904): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
06-09 14:53:11.684: E/AndroidRuntime(5904): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
06-09 14:53:11.684: E/AndroidRuntime(5904): at dalvik.system.NativeStart.main(Native Method)
06-09 14:53:11.684: E/AndroidRuntime(5904): Caused by: java.lang.IllegalArgumentException: layer must not be null
06-09 14:53:11.684: E/AndroidRuntime(5904): at org.mapsforge.map.layer.Layers.checkIsNull(Layers.java:43)
06-09 14:53:11.684: E/AndroidRuntime(5904): at org.mapsforge.map.layer.Layers.add(Layers.java:73)
06-09 14:53:11.684: E/AndroidRuntime(5904): at com.example.mapsforgerescueprova.MainActivity.onCreate(MainActivity.java:79)
06-09 14:53:11.684: E/AndroidRuntime(5904): at android.app.Activity.performCreate(Activity.java:5283)
06-09 14:53:11.684: E/AndroidRuntime(5904): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
06-09 14:53:11.684: E/AndroidRuntime(5904): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
06-09 14:53:11.684: E/AndroidRuntime(5904): ... 11 more
this.myLocationOverlay = new MyLocationOverlay(this, this.mapViewPositions.get(0), bitmap);
i put the code in onStart
@Override
protected void onStart() {
super.onStart();
this.mapView.getModel().mapViewPosition.setCenter(new LatLong(52.517037, 13.38886));
this.mapView.getModel().mapViewPosition.setZoomLevel((byte) 12);
// tile renderer layer using internal render theme
this.tileRendererLayer = new TileRendererLayer(tileCache,
this.mapView.getModel().mapViewPosition, false, AndroidGraphicFactory.INSTANCE);
tileRendererLayer.setMapFile(getMapFile());
tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.OSMARENDER);
// only once a layer is associated with a mapView the rendering starts
this.mapView.getLayerManager().getLayers().add(tileRendererLayer);
Drawable drawable = getResources().getDrawable(R.drawable.current_position);
Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
// create the overlay and tell it to follow the location
this.myLocationOverlay = new MyLocationOverlay(this, this.mapViewPositions.get(0), bitmap);
this.myLocationOverlay.setSnapToLocationEnabled(true);
this.mapView.getLayerManager().getLayers().add(this.myLocationOverlay);
this.myLocationOverlay.enableMyLocation(true);
}
this.myLocationOverlay = new MyLocationOverlay(this, mapView.getModel().mapViewPosition, bitmap);
instead of
this.myLocationOverlay = new MyLocationOverlay(this, this.mapViewPositions.get(0), bitmap);
Is ok?
protected void addOverlayLayers(Layers layers, LatLong geoPoint) {
Drawable drawable = getResources().getDrawable(R.drawable.current_position);
Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
myMarker = new Marker(geoPoint, bitmap, 0, 0);
layers.add(myMarker);
protected void removeOverlayLayers(Layers layers, LatLong geoPoint) {
layers.remove(myMarker);
<rule e="way" k="shop" v="doityourself" zoom-min="17">
<symbol src="jar:symbols/tools.png" />
</rule>
<rule e="way" k="shop" v="doityourself" >
<rule e="way" k="*" v="*" zoom-min="19">
<caption dy="38" k="name" font-family="default" font-style="bold" font-size="22" fill="#f187f8" stroke="#ffffff" stroke-width="3.0" />
</rule>
</rule>
--To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/c57e092b-acf5-4bcb-a0fa-74292d3547c4%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/2d40b345-e169-4881-af82-3f466a616771%40googlegroups.com.
I thought this was only available in dev
--
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/69b76449-862a-4289-8b7c-d9e5631ff6a2%40googlegroups.com.