Showing posts with label Android maps. Show all posts
Showing posts with label Android maps. Show all posts

How To Use Google Maps Android API v2-Part 1


How To Use Google Map  V2  For Android -Part 1

Since  Google Maps Android API as been officially deprecated as of December 3rd, 2012, We have to check Google Maps Android API v2  in detail.

For Documentation,please check https://developers.google.com/maps/documentation/android/intro

 Main Features  of Google Maps Android Api v2 :



The API allows you to add these graphics to a map:
  • Icons anchored to specific positions on the map (Markers).
  • Sets of line segments (Polylines) for drawing shapes.
  • Enclosed segments (Polygons), filled, unfilled or hollow.
  • Bitmap graphics anchored to specific positions on the map (Ground Overlays).
  • Sets of images which are displayed on top of the base map tiles (Tile Overlays).




In part 1,Iam going to mention the basic Map Loading....


Inorder to Use this,we have to add  Google Play Services as Library Project:It is inside our Android Sdk Folder-----


  Step 1: Add Google play service as lib project.
android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib

 Note: Download Google Play Services SDK for this.

Step 2:

     Add "android-support-v4.jar" in our "libs" folder.

 Step 3: 

     Login to Google Console using any Gmail account . 

 Step 4:

     After Login ,Create a Project using the  dropdown at the top left (Below    "Google Apis" text).Then Move to "Services" section and activate "Google Maps Android API v2" and "Google Maps API v2".

    Step 5: 

     After this, Select "API Access" and create key for android,For that we need SHA1 

  fingerprint and our project package name.This SHA 1 fingerprint is generated using  the 

command  prompt.Once successfully placed these ,a new key will be  generated  as API Key.



How To Use this in Our Project?
   


 Manifest File

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.trailmaster.app"
    android:versionCode="1"
    android:versionName="1.0" >

    <permission
        android:name="
packagename
.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="packagename.permission.MAPS_RECEIVE" /> <!-- Copied from Google Maps Library/AndroidManifest.xml. --> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.INTERNET" /> <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_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <application android:allowBackup="true" android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="XXXXXCMA8MyFORWXXXXXXXXXXXXXXXXXX" /> <activity android:name=".SampleActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>




  

In Main.xml:


    <fragment
                        android:id="@+id/map"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        class="com.google.android.gms.maps.SupportMapFragment" />
      
In Our java Class:
 
public class SampleActivit extends android.support.v4.app.FragmentActivity {
        private GoogleMap mMap;
        private SupportMapFragment mMapFragment;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
               setUpMapIfNeeded();
}


     private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
  // map.
  if (mMap == null) {
   // Try to obtain the map from the SupportMapFragment.
   mMapFragment = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map));
   mMap = mMapFragment.getMap();
   
   
  }
 }



Stay Tuned For Part 2(CUSTOM TILE OVERLAY IN GOOGLE MAP)------Happy Coding!
   

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