Setup Google developer console for an Android Map app

Setup Google developer console for an Android Map app

  • Login with your Gmail account.
  • Activate the Google Maps Android API v2 (you can enable any service for your account, for example, map service, youtube service.... etc).

  • Register a public access key with the SSA-1 key, which is copied when we export our project into bin folder with debug-keystone (you can export in a different location with your existing keystone).

  • Register an SSA key



  • Define the below code chunk in manifest file.
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


  • Define the below code inside the <application> tag which is located in manifest.
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAoJUCRMi6crD9Z1JMAWruWHig95z-uS50" />


  • Put your map fragment inside the activity_main.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/map"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 class="com.google.android.gms.maps.SupportMapFragment"/>


  • In Java implementation, for  a particular location with longitude and latitude 

GoogleMap map = ((SupportMapFragment) getActivity()
     .getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
LatLng nawala = new LatLng(6.9000, 79.88);// latitude, longitude

MarkerOptions mo = new MarkerOptions();
mo.position(nawala);
mo.title("Nawala");
map.addMarker(mo);

Comments

Popular posts from this blog

Programmatically turn ON/OFF NFC in Android

Sign-on by using Google OAuth2

Setup to execute Apache Spark in Cloudera