Prezi

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in the manual

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

A Simple example about using Google Maps Android API v2 painlessly (For Android App Developer)

No description
by Carl Adler on 18 July 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of A Simple example about using Google Maps Android API v2 painlessly (For Android App Developer)

Obtain Your Own API KEY
To access Google Maps, we need to add MAPs API Key to

the apps, here are something we need to do:

Generate certificate fingerprint(SHA1)

Creating an API Project

Obtaining an API Key

Adding the API Key to your application
Setup Your Development Environment
"Sharp Tools Make Good Work."

Before we go on, we need a good environment to develop.

In this step, we need to prepare the following things:

Android SDK

IDE (In this example, I use
Eclipse
.)

Some settings in our project.
Customizing The AndroidManifest.xml
The file "
AndroidManifest.xml
" is necessary for every

android program, in this example, we need to do the

following things:

Application Setting

Permission Setting

Feature Setting

...and so on.
Add A Simple Map In Your App
When you've done all the above steps, you can add a

map in your app, it's quick and easy. All you have to

worry about is the application target version. Of course,

we'll talk it later.
Install The .APK And Check The Result
Carl Adler
(C.A.)
yotsuba1022@gmail.com

A Simple example about using Google Maps Android API v2 painlessly
(For Android App Developer)

The main steps to use
Google Maps Android API v2

The final step is to install your app on a
real device
,

here you should notice that with Google Maps

Android API v2,
you can not run your map in

emulator
, maybe google will fix it someday. But now,

you really need a real device.
Open The Android SDK Manager
Download The Android SDK
http://developer.android.com/sdk/index.html
Install All The Things You Need
Import Google Play services As Library
Import Library and some settings...
Setup Your Development Environment
Go to
and download the android SDK.
After downloading, you may find out
eclipse.exe
in

folder
adt-bundle-windows-x86_64\eclipse
(My

OS is 64-bit, please choose the download

verssion correctly accroding to your device). Open

your eclipse, and then choose
Window->Android

SDK Manager
.
Here, except installing the API, you should also

install the
Google Play services
in
Extras folder
.
Check the install path.
In tool bar, choose
File -> Import
, then

choose Google Play services you installed.
Create Your Project
Now you can create your project, click

File -> Android Application Project.

Here you should notice the

Minimun Required SDK

you choose, in this example, I choose API 12 for

min, API 17 for target and

Google APIs(API 17) for

Compile
.
After create the project, you should import

Google Play services as a library, right click on your

project and choose "Properties". Click "Android" on left

side, and add Google Play services. Finally, add the

following code in your"
proguardproject.txt
"
-keep class * extends java.util.ListResourceBundle {

protected Object[][] getContents();

}
Generate certificate fingerprint(SHA1)
About API Key...
Generate certificate fingerprint(SHA1)
Creating an API Project
Adding the API Key to your application
Obtain Your Own API KEY
The key has two type:

Key for develope

Key for release

To obtain both key, you need to get the certificate

fingerprint(SHA1) separately. And the way to

generate certificate fingerprint is using the

xxx.keystore
in your computer.
The default xxx.keystore in your computer is named debug.keystore,

and it locate at the path "
C:\Users\your_user_name\.android\
".
Obtaining An API Key
You have to add a
Maps API key
to your app so that you can access

the Google Maps servers with the Maps API. Also, here're something

you should know:

The Key is free.

Any of your apps can call the Maps API with the key.

Unlimited users.

You should obtain the key from
Google APIs Console
by your app's


signing certificate
and the specific
package name
.
keytool -list -v -keystore "path_of_your_debug.keystore" -alias androiddebugkey -storepass android -keypass android
Generate Certificate Fingerprint(for develope)
Generate Certificate Fingerprint(for release)
Because there has no any keystore file for release, so you have to generate

one first, please using the following command:
keytool -genkey -v -keystore "your_keystore_name" -alias "alias_name" -keyalg RSA
-keysize 2048 -validity 10000
Here, you need to type some information...
After generate a keystore for release, you can now obtain the

SHA1 for release with the command:
keytool -list -v -keystore "your_keystore_name"
And here you need to provide your keystore password.
In this step, you need to create your own API Project and activate the

service you need. First, go to "
https://code.google.com/apis/console/
".
Click "Create project"!!
Choose
"Services".
Drop down the page, and you'll see the two services in the

picture below. Here you should choose "
Google Maps Android

API v2
", not "
Google Maps API v2
", cuz we're developing for

mobile device...
I think you must know what to do...
OK, so now you can check the services you've activated,

click "Active" on the top, you might see like the following picture.
After activate the service you need, you can now

click "
API Access
" and press the

"Create new Android key...".
Here you should enter your certificate fingerprint(SHA1) and the package

name. If your app is in the phase of development, you can use SHA1 for

develop; if the app is for release ver., use SHA1 for release.
Now you've applied for an API key for your app!

Copy the API key and we'll use it in the app.
Go back to your project, find

"
AndroidManifest.xml
", and add something to it.
In <application> tag, add the following tag:


<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your_api_key" />
In AndroidManifest.xml, add the following things:

<permission android:name="your_package_name.permission.MAPS_RECEIVE" android:protectionLevel="signature" />

<uses-permission android:name="your_package_name.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-feature android:glEsVersion="0x00020000" android:required="true" />
For more informations about these tags, please study this page:

https://developers.google.com/maps/documentation/android/start
Modify The Activity.java
Modify Your main.xml
Test In Emulator
Export Your App To APK File
Install The APK On Device And Run
Add a map to your app
and test it!

In your project, find the main.xml(maybe other name, but

you should know what name it is.), and replace all the

content with the following code:
Modify the Activity.java(Not always this name, you

know.) as below.
Open your ADV Manager in IDE to choose or new a

virtual device you prefer. Then run your app in the

emulator.
I think your screen might looks like below, cuz at this time(2013/2/25), the

emulator still doesn't support Google Play services. Well, there's still another

way to make it works, but this is not the topic in this tutorial, if you're

interested in it, just google it.
Right click on your project, choose Export -> Android ->

Export Android Application, choose the keystore and alias you

want to use. And don't forget the password you set before.

Finally, select the destination to generate your apk file.
The last step is to connect to your real device and

install the apk. Here, I use SONY Xperia ion as my

device, just choose a device you like and enjoy the

result. If your app doesn't work or crash, please

confirm that you've completed all of the steps

appearing earlier in this tutorial.
Thank you for your attention!
See the full transcript