osm in android device

Hi friends, I’m newbie, and I haven’t idea of how make a sample with osm in eclipse.
I need test osm in android device, and for this I’ve eclipse…but I don’t know how start…I’ve searched in internet but didn’t find anything…I’ll be very grateful if you pass me any link with tutorials…

For starting, what I need, is know how install osm in eclipse, in order to know it, in order to test it in android.

Later, I’ll need to know about things like: locate users (draw points in the map), draw routes given two coordinates, interact with divs…this is possible? I hope that yes…

Thanks very much in advance, Daniel

How good is your Java knowledge? Sounds like “absolutely nothing”. Eclipse is a Java IDE and can be used in conjunction with ADT (Android Development Tools) for Android development. To use data from OSM in Android there’s a free library: mapsforge. It can be used to display online tiles as well as offline vector maps (converted with a filter for osmosis). But this requires a lot of Java knowledge and I’m not sure if you are able to do what you have planned.

Right now, I’m in this point. I’ve created a new android project, included osmdroid-android-3.0.8.jar and slf4j-android-1.5.8.jar within a new directory /libs. Added these two .jar to the build.


public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        MapView mapView = new MapView(this, 256);
        mapView.setClickable(true);
        mapView.setBuiltInZoomControls(true);
        
        mapView.getController().setZoom(10);
        mapView.getController().setCenter(new GeoPoint(53.550657, 9.995499));
        setContentView(mapView);
    }

AndroidManifest.xml:


<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

main.xml:

 
<org.osmdroid.views.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"

	/>

Now, I execute the project, and I only see zoom buttons, and empties grids…
Could you help me?
Thanks, Daniel

Hello,
I’m new to this too :slight_smile:
I start today on doing something like you, for now i’m having the same problem. But for now i’m only trying examples that i found online.
I apreciate the help if anyone can give some hints.

I will probably use the mapnik to render the imgs, i already try to export the map for my city in the osm site, in the export option, but the result is not what i was expeting, only a few imgs is downloaded with a very smal size of bits.
For now i’m only trying the get the map with diferent lod’s and representing them on my android app.

Thanks, and sorry for my inglish

i have the same problem.

here can u see what the emulator shows: http://s1.directupload.net/file/d/3082/dz7tm4ei_jpg.htm

my code:


import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import org.osmdroid.views.overlay.SimpleLocationOverlay;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {

        TextView longitude, latitude;
        private MapView mapView;
        private MapController mapController;
        private ScaleBarOverlay mScaleBarOverlay;
        private SimpleLocationOverlay mMyLocationOverlay;
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        longitude = (TextView)findViewById(R.id.textViewLong);
        latitude = (TextView)findViewById(R.id.textViewLat);
        
        mapView = (MapView) this.findViewById(R.id.mapview);
        mapView.setClickable(true);
        mapView.setBuiltInZoomControls(true);              
        mapView.getController().setZoom(15);
        mapView.getController().setCenter(new GeoPoint(52.221,6.893));
        
        LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        LocationListener ll = new myLocationListener();
        
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
    }
    
    class myLocationListener implements LocationListener {

        @Override
        public void onLocationChanged(Location location) {
            if(location != null)
            {
                double pLong = location.getLongitude();
                double plat = location.getLatitude();
                
                longitude.setText(Double.toString(pLong));
                latitude.setText(Double.toString(plat));
            }
            
        }

        @Override
        public void onProviderDisabled(String provider) {
            Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);                
        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub
            
        }

        @Override
        public void onStatusChanged(String provider, int status,
                Bundle extras) {
            // TODO Auto-generated method stub
            
        }
        
    }
    
    public void ExitKlick(View v){
        this.finish();
    }

  
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

layout.xml:


RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="30dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Longitude:"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/textViewLong"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/linearLayout1"
        android:layout_marginTop="5dp" >

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Latitude:"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/textViewLat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Your Position via OSM"
            android:textStyle="bold" />
    </LinearLayout>

    
    <org.osmdroid.views.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/buttonExit"
        android:layout_below="@+id/linearLayout2">

    </org.osmdroid.views.MapView>
    
    <Button
        android:id="@+id/buttonExit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:onClick="ExitKlick"
        android:text="Exit" />

</RelativeLayout>

i added following libraries:
osmdroid-android-3.0.8 und
slf4j-android-1.5.8

can someone tell me, what i am doing wrong and how i can fix it. thanks in advance

The installation is not very difficult, here are the things you are required :

Java - 1.6, 1.7 (compile target is 1.6!)
Eclipse - 3.3, 3.4, 3.5 (version is undefined, newer the better)
Android SDK + android eclipse plugin
Optionally Andriod NDK (native code)
EGit - git plugin for eclipse (can not do everything yet)
Downloads : tile maps, osm (osm.bz2) vector map depends on the area you want to work to. For country Belarus (Minsk) you can download directly from the “downloads”
Details
Java is required 1.6 (you can download from jdk6.dev.java.net - download jdk to get source for base java classes
Android SDK is required developer.android.com/sdk/installing/index.html (You will be required for 2 versions 1.6 & 2.2)
(Optional) Android NDK is required if you want to change and compile native code (http://developer.android.com/tools/sdk/ndk/index.html
Eclipse you can download eclipse.org/downloads- ! run the eclipse with more memory, 32 bit around 512MB, 64 bit around 1GB. Android tools take lot of memory to compile the project !
You will need eclipse android plugin developer.android.com/tools/sdk/eclipse-adt.html
Optional you can install EGit, git plug-in for eclipse eclipse.org/egit/. Or you can stick with some other git tool
To see results how you are working you also need map data :
To create tile maps you can use (MobileAtlasCreator) : create tiles for OSMtracker tile storage (now ‘Mapnik’ as source map is hardcoded), please use it.
You can find osm map for country through special sites. You can download small part of osm for town through JOSM (as example)
You also can use internet : both swing application & android application can download tiles by itself from internet.
Install repo utility.
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
Check out the project from repository.
$ repo init -u git://github.com/osmandapp/OsmAnd-manifest.git
$ repo sync
You can make your fork on github and work with it and do pull-requests to publish your work in OsmAnd’s repository.
Import OsmAnd (from /platforms/android) and OsmAndMapCreator (from /tools/) and OsmAnd-java (from /core/) projects from into eclipse (do not copy them to workspace). See plugins directory, where can be some plugin projects you can contribute to.
Make sure that eclipse android plugin refers to android sdk path (Preferences → Android → SDK)
(Optional, should work out of box) Check external folder in OsmAnd project : specify that use refers to OsmAnd-java/src (use path variable to have common version in reposititory).
Try to compile all projects to get rid of the errors or try to run Ant script alternatively.
Configure local.properties (look at sample file) in OsmAnd project in order to run OsmAnd\build.xml. Run Ant file OsmAnd\build.xml and get OsmAnd-debug.apk ready.
Config Application
You can run OsmExtractionUI.class and it is OsmAndMapCreator
If you want to enable logging - do not forget to put Java VM arg -Djava.util.logging.config.file=logging.properties
After that you can try to run Swing (standalone) application to see whatever result.

If you did all, possibly you installed development environment on your machine.


bonuspress bonus

I think this url is helpful for you a little bit about it.
wiki.eclipse.org/Eclipse/Installation#Install_a_JVM
here you can find the some tips about the Java and Eclipse installation.

Hi,
I used some mapsforge converted vector maps and I want to edit them. Is it possible? What editor do I need, JOSM?
Sorry, may be it is not the right place to ask this question but I could not find any other…

Please open a new topic on this Android sub forum here, with a clear headline.