Tutorial Android Google Maps Sederhana
Semoga hari ini berkah untuk kita semua, di sini saya ingi berbagi sedikit tantang pembelajaran pemrograman yang saya
jalani, yaitu : Tutorial Membuat Maps Sederhana dengan menggunakan Android Studio.
1. Tahap pertama:
Buka Android Studio anda → Flie → New → New Projects → Google Maps Activity
2. Tahap kedua:
Disini kita akan menentukan Name, Package Name, Save Location, Language (Java / Kotlin).
3. Tahap ketiga:
Setelah tahap di atas selesai maka kita, akan memiliki 3 file ini;
- MapsActivity.java / MapsActivity.kt
- activity_maps.xml
- google_maps_api.xml
4. Tahap keempat:
- Buat kunci API
Buka file google_maps_api.xml lalu copy URL yang ada, buka di browser maka akan tampil seperti ini
Jika belum memiliki project silahkan pilih Buat Project, namun jika mau menambahkan kunci ke project yang sudah ada
silahkan pilih project yang mau di tambahkan. Lalu pilih domisili negara sesuai negara teman-teman, jangan lupa untuk
menconteng syarat yang dan minta dan untuk menyelesaiakn pilih setuju dan lanjutkan.
Jika sudah siap, pilih Buat kunci API, tunggu beberapa saat, jika sudah selesai maka akan tampil seperti ini
Pembuatan kunci API telah selesai, copy Kunci taruh
di google_maps_api.xml → YOUR_KEY_HERE
Jalankan aplikasi dan tara aplikasi maps sederhana telah selesai, terimakasih atas kunjungan teman-teman semoga
bermanfaat.
Source Code.
1. Tahap pertama:
Buka Android Studio anda → Flie → New → New Projects → Google Maps Activity

Disini kita akan menentukan Name, Package Name, Save Location, Language (Java / Kotlin).

Setelah tahap di atas selesai maka kita, akan memiliki 3 file ini;
- MapsActivity.java / MapsActivity.kt
- activity_maps.xml
- google_maps_api.xml

- Buat kunci API
Buka file google_maps_api.xml lalu copy URL yang ada, buka di browser maka akan tampil seperti ini


Jika sudah siap, pilih Buat kunci API, tunggu beberapa saat, jika sudah selesai maka akan tampil seperti ini

di google_maps_api.xml → YOUR_KEY_HERE

Source Code.
1. MapsActivity.kt
package com.temancoding.myapplication import android.support.v7.app.AppCompatActivity 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 class MapsActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mMap: GoogleMap override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_maps) // Obtain the SupportMapFragment and get notified when the map is ready to be used. val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as SupportMapFragment mapFragment.getMapAsync(this) } /** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ override fun onMapReady(googleMap: GoogleMap) { mMap = googleMap // Add a marker in Sydney and move the camera val sydney = LatLng(-34.0, 151.0) mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney")) mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)) } }
2. activity_maps.xml
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map" tools:context=".MapsActivity" android:name="com.google.android.gms.maps.SupportMapFragment">
3. google_maps_api.xml
<resources/> <!-- TODO: Before you run your application, you need a Google Maps API key. To get one, follow this link, follow the directions and press "Create" at the end: https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=87:5C:CA:14:3C:56:C6:5F:22:38:A4:8C:27:BA:83:77:C7:83:F3:A8%3Bcom.temancoding.myapplication You can also add your credentials to an existing key, using these values: Package name: 87:5C:CA:14:3C:56:C6:5F:22:38:A4:8C:27:BA:83:77:C7:83:F3:A8 SHA-1 certificate fingerprint: 87:5C:CA:14:3C:56:C6:5F:22:38:A4:8C:27:BA:83:77:C7:83:F3:A8 Alternatively, follow the directions here: https://developers.google.com/maps/documentation/android/start#get-key Once you have your key (it starts with "AIza"), replace the "google_maps_key" string in this file. --> <string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">GANTI_INI_DENGAN_KUNCI_API_KAMU</string> </resources>
Belum ada Komentar untuk "Tutorial Android Google Maps Sederhana"
Posting Komentar