Questions from a beginner.

151 views
Skip to first unread message

Devdatta Tengshe

unread,
Dec 28, 2012, 2:27:17 AM12/28/12
to mapsfo...@googlegroups.com
Hi all,
I want to put a map in my Android App. I am new to Android development, so please forgive my naive questions if any.

I downloaded an map.osm file from OpenStreetMaps. I converted it to a .map file using the instructions given on Mapsforge Map-Writer page
I have downloaded the code for both the samples and the AdvancedMapViewer application. I could successfully build them. I could also open my map file in the AdvancedMapViewer application successfully. It opens the map at extent where you can see all the data.
But when I run the BasicMapViewer from the samples, the map loads the data in a zoomed-out view (see the attached image.) So here are my questions:

1) How do I get the map to open in a zoomed-in view like the AdvancedMapViewer? I tried to find that code in the source code, but could not find it.

2) Once we have a .map file, do we have to create the tiles, or are they created by the mapsforge library?

3) How do I get the point on the map, that the user clicks on?

4)If I have a few overlays in my map, how do get the one that the user has clicked on?

Regards,
Dev
device-2012-12-28-125003.png

Hila

unread,
Dec 28, 2012, 12:23:30 PM12/28/12
to mapsfo...@googlegroups.com
0. First- use version 0.3.0, since the overlays in that version support 'OnLongPress' and 'OnTap'

1. I guess you mean this method: mapView.setCenter(GeoPoint geoPoint)

2. you don't have to do anything. simply load the "XXX.map" to the mapview, and the mapview handles its display.

3+4. inherent from class Overlay. create an overlay that implements the methods 'OnTap' and 'OnLongPress'.
these method returns the geoPoint of the point the user touched/tapped.

in order to get a specific overlay from list of overlay, you can use inherent from ArrayItemizedOverlay, and implement onTap(int index).
so when you have let's say many gas stations on the map, and the user clicks on one,
the 'OnTap(index)' will be called, so you'll get the item this way:
OverlayItem item = createItem(index);


goodluck

Hila

unread,
Jan 24, 2013, 9:11:55 AM1/24/13
to mapsfo...@googlegroups.com


Here is an example for version 0.3.0, for onTap and OnLongPress.


public class GeneralMapOverlay extends ArrayItemizedOverlay {
private final Context context;
//private final Drawable mDefaultMarker;
public GeneralMapOverlay(Drawable defaultMarker, boolean alignMarker, Context context) {
super(defaultMarker, alignMarker);
this.context = context;
//.mDefaultMarker = defaultMarker;
}
/**
 * Handles a tap event on the given item.
 */
@Override
protected boolean onTap(int index) {
OverlayItem item = createItem(index);
long ID = Long.valueOf(item.getTitle()).longValue();
Intent intent = new Intent(context.getApplicationContext(), OverlayItemViewer.class);
intent.putExtra(OverlayItemViewer.INTENT_IN_DATA_OVERYLAY_VIEWER_OVERLAY_ID, ID);
intent.putExtra(OverlayItemViewer.INTENT_IN_DATA_OVERYLAY_VIEWER_OVERLAY_TYPE, 
OverlayItemViewer.INTENT_IN_DATA_OVERYLAY_VIEWER_OVERLAY_TYPE_GENERAL);

context.startActivity(intent);
return true;
}

        // This is not part of the original code,
        // it's here so you can see how to use OnLongPress
        @Override
public boolean onLongPress(GeoPoint geoPoint, MapView mapView) {
touchedGeoPoint = geoPoint;
touchedMapView = mapView;
((Activity) this.context).runOnUiThread(updateRunnable);
return true;
}
@Override
protected void drawOverlayBitmap(Canvas canvas, Point drawPosition, Projection projection, byte drawZoomLevel) {
     // TODO put zoom in preference
if (drawZoomLevel > 8){
super.drawOverlayBitmap(canvas, drawPosition, projection, drawZoomLevel); 
     }
}




On Thursday, January 24, 2013 2:10:12 PM UTC+2, byteworks wrote:

Do you have any example to do 3+4 maybe, Hila? Would be much appreciated!
Reply all
Reply to author
Forward
0 new messages