Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Set Google Map API v2 in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 504
    Comment on it

    Set Google map in android application

    To get a google map view in your android application .First you have to create your Google Api Key on the following link https://code.google.com/apis/console/ .

    First make a project on the Google API Console then turn on the Google map services Google Maps Android API v2, Google Maps API v3,Google Maps Coordinate API and Google Play Android Developer API .

    After this go to API access to create the unique api key for your project. Click on Create api key, then put your SHA 1 Finger Prints and your package name separated by the semicolon. get your SHA 1 finger Prints from Eclipse->Windows->Preferences>android>Build

    Put the SHA 1 finger print and package name.

    Example: DE:13:23:14:4C:7E:95:F6:27:DC:29:3A:39:9E:84:B9:A7:DE:1F:53;com.example.setmaplocation

    Put the generated api key in the manifest file. in meta data tag.

    Open Eclipse Windows Android SDK Manager and check whether you have already downloaded Google Play Services or not under Extras section. If not select play services and install the package.

    In Eclipse goto File Import Android Existing Android Code Into Workspace. Click on Browse and select Google Play Services project from your android sdk folder. You can locate play services library project from android-sdk-windows\extras\google\google_play_services\libproject\google-play-services_lib.

    Then make the following activity. sample code

    package com.example.setmaplocation;
    
    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;
    import android.view.Menu;
    
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.SupportMapFragment;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.MarkerOptions;
    
    public class MainActivity extends FragmentActivity {
    
        private GoogleMap googleMap;
        double latitude = 21.0000;
        double longitude = 78.0000;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            System.out.println("In Oncreate");
    
            try {
                // Loading map
                initilizeMap();
    
            } catch (Exception e) {
                e.printStackTrace();
            }
    
    
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
    
            return true;
    
        }
    
        private void initilizeMap() {
    
    
            if (googleMap == null) {
                // Try to obtain the map from the SupportMapFragment.
                googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                        .getMap();
                // Check if we were successful in obtaining the map.
                if (googleMap != null) {
    
                    MarkerOptions marker = new MarkerOptions().position(
                            new LatLng(latitude, longitude)).title("Hello Maps ");
    
                    googleMap.addMarker(marker);
    
                }
            }
    
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            initilizeMap();
        }
    
    }
    
    

    For further reference use the File that i have attached.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: