It seems that I will make an Android application using Google Map for various reasons, so I made it as a preparation. I am completely a beginner, so I would appreciate it if you could point out any mistakes or corrections.
Let's proceed on the premise that it has already ended.
First, install it. Go to ʻAndroid SDK-> SDK Tools-> Google Play services and apply with ʻApply
.
Next, make an association. Add compile'com.google.android.gms: play-services: +'
to build.gradle
.
build.gradle
dependencies {
...
compile 'com.google.android.gms:play-services:+'
}
Then, synchronize with Sync Now
that appears in the upper right corner of the screen.
Finally, add a manifest. Add the following element to the <application>
element of ʻAndroidManifest.xml`.
AndroidManifest.xml
...
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
Open a prompt and change to the JDK bin directory
. So do the following: Rewrite <user name>
as appropriate.
keytool -list -v -keystore "C:¥Users¥<User name>¥.android¥debug.keystore" -alias androiddebugkey -storepass android -keypass android"
You may see a lot, but make a copy of the hexadecimal numbers on the SHA1:
line.
Enter the Google Developers Console. Create a project with an appropriate name and enter the dashboard. It seems that the layout changes a little (?) On a regular basis, so if you don't have one, please look for it yourself.
Then click ʻEnable API and Services. ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/382909/2c2afab6-5208-594a-09d0-89cd9bed90f0.png) Search for the Google Map SDK for Android. ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/382909/27842b36-3780-50cf-d4f8-38732bfdce50.png) Activate the found SDK and move to the authentication information field. ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/382909/8908fc31-ae54-4a1b-e4fe-3c5c6ec97fa9.png) When you select the API key, the key is generated. Next, limit the API. ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/382909/bbc4baab-6351-a87a-613a-e0239da4bc39.png) Set ʻAndroid application
in Application restrictions
. Paste the package name and the SHA1 certificate you obtained earlier in the Limited use to Android apps
field. In most cases, the package name will be something like com.example.project name
.
Open the manifest file ʻAndroidManifest.xml and add the following in the
element. Write your API key in the
AndroidManifest.xml
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="<API key>"/>
Add the permission by writing the following in the <manifest>
element of ʻAndroidManifest.xml`.
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Add the following in the <manifest>
element of the manifest as well as permissions.
AndroidManifest.xml
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
Erase everything that was originally written and write the following code.
activity_main.xml
<fragment android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/map"
xmlns:android="http://schemas.android.com/apk/res/android" />
Delete everything except the package com.example.name
on the first line. Then add the following code.
MainActivity.java
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
public class MainActivity extends AppCompatActivity {
MapFragment mf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mf = MapFragment.newInstance();
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(android.R.id.content, mf);
ft.commit();
}
}
Emulator execution screen.
Use Google Map API in Android Studio Use Google Map for Android application development
Recommended Posts