Android Tutorial: integrating Google Map V2 in an Android app with Android Studio
Integrating Google Map V2 in an Android
If you want to include Google Maps V2 in your Android app using Android Studio,you must follow steps below:1. In your SDK Manager, make sure that the Google Play Services is installed.
2. To get your MAP key from Google console, you must have the SHA1 key to your IDE (Android Studio). You must use the following command in your command prompt:
(this command line must be executed in the" /bin" folder of the JDK used by Android Studio).keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
Note the SHA1 key provided. It is needed later.
3. Create a new project.
4. Now you have to get a free API key to your application. Sign in Google Developers Console API:
https://console.developers.google.com. Click the Create Project button. Next, you need enabling Google Maps v2 API for Android Click afterwards on "credentials" that is under the API and authentication menu at the top left. Click add credentials (choose API key) and click on Android key. Finally, click Add name of the package and so you must paste the name of the package in the area that is dedicated to it and the same for the SHA1 key. Next, click Create. This will generate an API key that you will use in your Android application.5. In your module build.gradle, insert the following in the dependencies (see picture bellow):
1
2
3
4
5
| dependencies { ... compile 'com.google.android.gms:play-services-maps:6.5.87' ... } |
<permission android:name="yourPackageName.permission.MAPS_RECEIVE" />
<uses-permission android:name="yourPackageName.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
You should also add the following tag at the Application tag. You have to put your key generated by Google Developer Console API instead of generated_api_key_by_google.
<
meta-data
android:name
=
"com.google.android.maps.v2.API_KEY"
android:value
=
"generated_api_key_by_google"
/>
android:layout_height
=
"match_parent"
android:paddingLeft
=
"@dimen/activity_horizontal_margin"
android:paddingRight
=
"@dimen/activity_horizontal_margin"
android:paddingTop
=
"@dimen/activity_vertical_margin"
android:paddingBottom
=
"@dimen/activity_vertical_margin"
tools:context
=
".MainActivity"
>
<
fragment
android:id
=
"@+id/map"
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
class
=
"com.google.android.gms.maps.MapFragment"
/>
</
RelativeLayout
>
Commentaires
Enregistrer un commentaire
Your comment will be reviewed by moderators