Google Maps V2 for Android Application

I waited so long to write this blog, but due to lack of time, here I will discuss the secret behind interfacing (using) Google Maps V2 in your own Android Applications.

Steps involved

1) Maps belongs to Google, hence in order to use them in our application, we need to get respected support libraries from them. They (Google) placed these libraries in Google Play services. You can download and install the same in your Android Developer Tool (ADT) by navigating Window > Android SDK Manager and check Google Play Services and click Install packages …

1

2) And you have required libraries to use in your app, import the same libraries into your current workspace

You may find them at adt-bundle-linux-x86-XXXXXX/sdk/extras/google/google_play_services/libproject/google-play-services_lib

Note: don’t forget to check Copy projects into workspace

5

3) Create a New Android Application Project in Eclipse

4) Get SHA1 fingerprint of your ADT at Window > Android > Build

7.3

5) Get API_KEY

  1. Open browser type google.com and search for api console click the first link of your searchGoogle
  2. Sign in with your gmail accountapi
  3. Click Services and turn ONGoogle Maps Android API v2 from All Services7
  4. Click API Access > Create new Android key … 7.1
  5. You will get a pop up menu, enter your SHA1 fingerprint ; package name and then click Create7.4

6.  You will get an Api Key at the top, copy it for further procedure, thats it Sign out

7.5

6) Come back to your project, paste the API key at manifest of your project as below inside the <application></application> tag,

<meta-data android:name=”com.google.android.maps.v2.API_KEY” android:value=”AIzaSyCTUN9NUi3IRgIVncVwh-2R-WXa7JDABYE”/>

7)  Get the following permissions in manifest.xml

<uses-feature android:required=”true” 

android:glEsVersion=”0x00020000″/>

<uses-permission android:name=”android.permission.INTERNET”/>
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>

<uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION”/>
<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”/>
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/>

<uses-permission android:name=”com.wordpress.smdaudhilbe.mymapdemoo.permission.MAPS_RECEIVE”/>
<uses-permission android:name=”com.google.android.providers.gsf.READ_GSERVICES”/>

<permission android:name=”com.wordpress.smdaudhilbe.mymapdemoo.permission.MAPS_RECEIVE”></permission>

ACCESS_NETWORK_STATE – To check network state whether data can be downloaded or not
INTERNET – To check internet connection status
WRITE_EXTERNAL_STORAGE – To write to external storage as google maps store map data in external storage
ACCESS_COARSE_LOCATION – To determine user’s location using WiFi and mobile cell data
ACCESS_FINE_LOCATION – To determine user’s location using GPS
OpenGL ES V2 – Required for Google Maps V2

Finally your manifest.xml file should be like

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
package=”com.wordpress.smdaudhilbe.mymapdemoo”
android:versionCode=”1″
android:versionName=”1.0″ >

<uses-sdk
android:minSdkVersion=”11″
android:targetSdkVersion=”17″ />

<uses-feature android:required=”true” 

android:glEsVersion=”0x00020000″/>

<uses-permission android:name=”android.permission.INTERNET”/>

<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/> 

<uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION”/>
<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”/>
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/> 

<uses-permission android:name=”com.wordpress.smdaudhilbe.mymapdemoo.permission.MAPS_RECEIVE”/>
<uses-permission android:name=”com.google.android.providers.gsf.READ_GSERVICES”/>

<permission android:name=”com.wordpress.smdaudhilbe.mymapdemoo.permission.MAPS_RECEIVE”></permission> 

<application
android:allowBackup=”true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme” >
<activity
android:name=”com.wordpress.smdaudhilbe.mymapdemoo.MainActivity”
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.maps.v2.API_KEY” android:value=”AIzaSyCTUN9NUi3IRgIVncVwh-2R-WXa7JDABYE”/>
</application>

</manifest>

8) Now we need to make Google Play Services project as a library to our project, right click over the project and click Build_Path > Configure Build Path …

on

Click Add and select the google-play-services_lib

9

Check Is Library and click Apply

check

again uncheck Is Library

uncheck

Now Navigate to Java Build Path > Libraries and click Add External JARs …

11

Select google-play-services.jar by navigating to current-WorkSpace-of-your-project/google-play-services_lib/libs/google-play-services.jar

pil

Then click Order and Export and check all options given below

checkall

and finally click OK …

Tired ???

9) fill activity_main.xml as

<?xml version=”1.0″ encoding=”utf-8″?>
<fragment
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:tools=”http://schemas.android.com/apk/res-auto&#8221;
android:id=”@+id/MYMAP”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
class=”com.google.android.gms.maps.MapFragment”/>

10) Let us jump to coding now, open up MainActivity.java and fill

package com.wordpress.smdaudhilbe.mymapdemoo;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {

// Google Map
GoogleMap gMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Single line to show Map
gMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.MYMAP)).getMap();
}
}

Thats it …! You may see a white blank screen at your emulator so thing like below

Eager to see map test your app in real device, you may customize it according to your wish, best reference for this is http://www.androidhive.info

I done this at Linux platform, hope this helps anyone in need

Enjoy … !

UPDATE : 

I found good resource for Google Maps V2 here

UPDATE: date : 09 / 01 / 2014

Here is the new Manifest permissions for any map to work for KitKat and before

<!– map required permission –>
<uses-feature
android:required=”true”
android:glEsVersion=”0x00020000″/>

<uses-permission android:name=”android.permission.INTERNET”/>
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>
<uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION”/>
<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”/>
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/>

<uses-permission android:name=”com.wordpress.smdaudhilbe.bquiet.permission.MAPS_RECEIVE”/>
<uses-permission android:name=”com.google.android.providers.gsf.permission.READ_GSERVICES”/>

<permission android:name=”com.wordpress.smdaudhilbe.bquite.permission.MAPS_RECEIVE”
android:protectionLevel=”signature”/>

And additional meta-data,

<meta-data
android:name=”com.google.android.gms.version”
android:value=”@integer/google_play_services_version”/>

with old

<!– Map –>
<meta-data
android:name=”com.google.android.maps.v2.API_KEY”
android:value=”XXXXXXXX”/>

Your XML file should be,

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” >

<fragment
android:id=”@+id/MyMap”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
class=”com.google.android.gms.maps.MapFragment”/>

</RelativeLayout>

and finally class file,

// Google Map
GoogleMap gMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_fragment);

// get map
// gMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.MyMap)).getMap();
initializeMap();
}

// create map
private void initializeMap() {

if (gMap == null) {
gMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.MyMap)).getMap();

// check if map is created successfully or not
if (gMap == null)
Toast.makeText(getApplicationContext(),”Sorry! unable to create maps”, Toast.LENGTH_SHORT).show();
}
}

@Override
protected void onResume() {
super.onResume();
initializeMap();
}

Enjoy … !

Advertisements

LAMP (Linux Apache MySql PHP) server Installation for Linux (debian)

As like WAMP(Windows Apache MySql PHP) server for Windows, here I will show simple steps which I followed after failing more number of times.

Quick Installations step,

$ sudo aptitude install apache2 php5 mysql-server php5-mysql libapache2-mod-php5 

For MySQL give a root password when prompted.,

Restarting Apache webserver,

$sudo /etc/init.d/apache2 restart 

Type

 http://localhost 

in your browser.,

If you get this screen, you succeeded with apache webserver installation

Image

root of your website is always located at /var/www/ location.,

PHP testing,

Create a php file at /var/www/test.php

/* test.php */

<? phpinfo();?>

Open your browser at type,

 http://localhost/test.php 

Image

Hence you succeeded with LAMP installation., for more info

Enjoy…!

UPDATE:

Hi, after installation when I tried to use phpmyadmin  a very famous MySQL mangement software package by opening as

 http://localhost/phpmyadmin


It failed to open, I encountered OOPS! This link appears to be broken error after doing a lot research I found the way to solve this issue.

I found it here.,

Step 1: Install phpmyadmin package,

$ sudo apt-get install phpmyadmin

Step 2: Add the following line at /etc/apache2/apache2.conf

Include /etc/phpmyadmin/apache.conf

As per suggestion, I tried to open again as http://localhost/phpmyadmin but again failed.

Step 3: As per the given suggestion, type to redo the installation again

$ sudo dpkg-reconfigure -plow phpmyadmin

It will ask for user name and password, more number of times. Just enter “root” as username and “any preferred password” as password.

Again I failed to open http://localhost/phpmyadmin

Step 4: “If this does not work, then you can do the following to include the phpMyadmin-shipped Apache configuration into Apache:”

$ sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
$ sudo /etc/init.d/apache2 reload

At last, I succeeded http://localhost/phpmyadmin

f1

After entering “root” as the username and “my preferred password”, I succeeded

f2

Enjoy….! For more info

SQLite DataBase Browser in linux for Android Application Development

Hai Friends, many of you will struggle to get this SQLite DataBase Browser to get work in Linux platform. I found a link to download and make use of it as like in Windows.

Enjoy..!