I had a chance to use it in the development of my own Android application, so make a note of it. It can be used when you want to embed Google Map as part of the application.
You must be logged in with your Google account ★ How to create a Google account
Install Google Play services from AndroidStudio> Tool> SDK Manager
-Implement Google Play services in build.gradle
build.gradle
dependencies {
...
implementation 'com.google.android.gms:play-services:+'
}
Add the following after </ activity>
and between </ application>
AndroidManifest.xml
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Enable the Maps SDK for Android from the API Library (https://console.developers.google.com/apis/library?project=golfscoremanagement)
Create a project from Dashboard Project name: any name Location: If it is a self-made application, "no organization" is OK
After that, create credentials in the created project ・ Select the API key on this screen
Limit keys ・ At this point, your API key is created
Name: any name
Application Limits: Select Android App
Terminal
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
・ Execution result (example)
Terminal
SHA1: 0R:B9:4Z:33:22:33:AA:BB:CC:55:66:77:GG:88:77:12:34:AB:CD:PP
There is a SHA-1 fingerprint in the part that is displayed as "Zura". Select the "0R: B9: 4Z: 33: 22: 33: AA: BB: CC: 55: 66: 77: GG: 88: 77: 12: 34: AB: CD: PP" part Paste it on SHA-1 in step 4 and press the Finish button to save it.
After saving, check the API Key. (I will use it later)
Create and add google_map_api.xml to res> values
google_map_api.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">API Key</string>
</resources>
★ API Key is the one obtained in step 5 (the part written here)
Describe the following in <manifest>
(permission of Parmission)
AndroidManifest.xm
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Also add to Android Manifest (same location as Parmission)
AndroidManifest.xm
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
Add it below the meta-data added at the beginning
AndroidManifest.xm
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key"/>
</application>
Created on the assumption that it will be incorporated into an existing application.
MapActivity.java
MapActivity.java
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney, Australia, and move the camera.
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
activity_map.xml
activity_map.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Recommended Posts