Showing posts with label osmdroid. Show all posts
Showing posts with label osmdroid. Show all posts

Modifying OsmDroid in Android

Modifying OsmDroid in Android. 

Inorder to Modify osmdroid,we have to import it first.



How to import osmdroid-android project ?

While importing osmdroid-androi source,there may occur errors.
 So to avoid wastage of time ,we have to create a new java project "osmdroid-android" and place all files in "src" in the order it is from google svn checkout.
There contains other files like assets,bin etc and copy /create that also.Sometimes you have to import android.jar also.


After doing this ,suppose if we want a jar of this....

Follow the steps--------------
  1. Go to the Java Build Path (right click on your project in the navigator -> properties -> Java Build Path -> Libraries)
  2. Edit the “ANDROID_SDK_PLATFORM/android.jar” entry
  3. Click the “Variable” Button and add a new Variable called “ANDROID_SDK_PLATFORM” and your android platform folder as the desired path
  4. Back at the Build Path Libraries look inside the folder”JUnit 4″ and write down the filename of hamrest.core and the path of the junit.jar file – we’ll need them later
  5. change from Java Build Path to “Builders”
  6. Create a new Ant Builder and add the build.xml into “Buildfile” and select the project itself as Base Directory.
  7. Change to Tab “Target and click “Set Targets…” at the Manual Build Option
  8. Check “jar” in the selection and close with ok. There should be in the Manual Build: “build, jar”.
  9. Click Ok and be sure to have the new Ant builder active and the java Builder INACTIVE
  10. Open “build-jar.xml and delete in line 32 the following “depends=”version”
  11. Delete on line 37 “.r${version}
  12. Change on line 43 “destfile” to the folder where you want the Jar file to be created.
  13. Open build.xml and change the following lines
  14. 9 – at the value field enter your android platform folder
  15. 10 – at value enter your eclipse folder
  16. 16 and 17 – be sure the path and filename of the JUnit files are correct
  17. Run and hope that you get a Jar file at the end


Another Method for Creating Jar in Android
Select "osmdroid-android" project and click "Export".
In this,select "Java"-> "jar" and select what all files you want in your jar and 
finally  specify the destination path.

After creating the Modified Osmdroid jar,you can directly use in Android Project.


  

    


Open Street maps in Android -Part 2

Open Street maps in Android -Part 2

For knowing the basics of openstreet maps ,Refer 
http://androidtraininginkerala.blogspot.in/2013/01/open-street-maps-in-android-part-1.html


Today ,we have to check how to create offline map using osmdroid.For that we requires

Steps

1:Offline Map Source .

     Use MOBAC for creating offline map source.


2:After creating zip file,copy that file and paste it inside  /sdcard/osmdroid/
For eg: if our zipfile is "mymap.zip",then it should be like 
   /sdcard/osmdroid/mymap.zip

Folder Structure of mymap.zip
 " Mapnik->ZoomLevels->X value->Y.png "
Sample Code:
public class OsmdroidDemoMap extends Activity {

    private MapView         mMapView;
    private MapController   mMapController;

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);



         MapView mapView = new MapView(this, 256); //constructor
         mMapController=mapView.getController();
         mapView.setClickable(true);

         mapView.setBuiltInZoomControls(true);
         mapView.setMultiTouchControls(true);
         setContentView(mapView); 
          mapView.getController().setZoom(5); your need

         mMapController.setCenter(new GeoPoint(10.5649,-20.7097)); 

         mapView.setUseDataConnection(true);
       }
        
    }

  

    


Open Street Maps in Android--Part 1

Open Street Maps in Android--Part 1

Open Street Maps (Osmdroid) is mainly used as an alternative for Google Maps.The main Advantage of

this is the use of offline access.

To use this map, we requires 

1: Latest osmdroid jar (osmdroid-android-3.0.8.jar)
2: slf4j-android-1.5.8.jar

you can check out the project from 

https://code.google.com/p/osmdroid/


Sample Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <org.osmdroid.views.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true" />

</LinearLayout>

OsmdroidDemoMap.java
 public class OsmdroidDemoMap extends Activity {

    private MapView         mMapView;
    private MapController   mMapController;

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
    MapView map = (MapView) findViewById(R.id.map);
    map.setTileSource(TileSourceFactory.MAPNIK);   
    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);
    map.getController().setZoom(16);
    map.getController().setCenter(new GeoPoint(30266000, -97739000));
}  
Manifest Permissions
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_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" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


 

Popular Posts

About Me

Only For Sharing Android Related Things...

Facebook Fan Page