Friday, 17 January 2014

Google Map with Photos

                                                  GoogleMapV2



NOTE: Version 1 of the Google Maps Android API has been officially deprecated as of December 3rd, 2012 . This means that from March 3rd , 2013 you will no longer will able to request an API key for this  version. No new features will be added to Google Maps API v1 . However , apps using v1 will continue work on devices. Existing and new developers are encouraged to use Google Maps Android API v2.


NOTE: You cannot run your application using Google Play API(Google Maps Android API V2) on Android emulator, Because your emulator doesn't support Google Play services. So you need to check your application in Android mobile phone which supports google play services.


Step:1

 GoogMapAccess.java

 package com.example.crudapps;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class GoogMapAccess extends Activity {

  
    GoogleMap googleMap;
    double latitude = 13.003597;
    double longitude =80.202485;
  
    private final LatLng KIEL = new LatLng(13.003597,80.202485);
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_goog_map_access);
      
        googleMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map_simple)).getMap();
      
      
        LatLng latLng = new LatLng(latitude, longitude);
        googleMap.addMarker(new MarkerOptions().position(latLng));
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
      //  googleMap.icon(BitmapDescriptorFactory.fromResource(R.drawable.chandru));
        

       googleMap.addMarker(new MarkerOptions()
        .position(KIEL).title("chandru home").snippet("Population: 4,627,300")        .icon(BitmapDescriptorFactory.fromResource(R.drawable.chandru)));
      
        googleMap.setOnMapClickListener(new OnMapClickListener() {
          
            @Override
            public void onMapClick(LatLng latlng) {
              
                Log.i("just location showing in map","Latitude"+latitude+"Longitude"+longitude);
              
            }
        });
      
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.goog_map_access, menu);
        return true;
    }

  
}


Step:2

activity_goog_map_access.xml


<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map_simple"
   android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />



Step:3

AndroidManifest.xml

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

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="21" />

   
    <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
   
    <permission
        android:name="com.example.crudapps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.crudapps.permission.MAPS_RECEIVE" />
   
   
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".GoogMapAccess"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
             
       
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyBY3ouErTfhFXk6FyIv50zGiPMb7agoOgMS" />
       
    </application>

</manifest>



 Step:4

 Add googleplayservicelib.



Screen Sample:

                                                                                       only Marker


Add Image

                                                      

Download Source Code:

Full source code for Googe Map in andorid


 

No comments:

Post a Comment