Tutorial Menampilkan Google Map Android API v2 di Android Studio

Posted on
Uji Coba Hasil
Tutorial menampilkan peta di android, itu tidak sesulit yang kita pikirkan. sekarang banyak media informasi yang memanfaatkan SIG untuk mempermudah sebagai penunjuk lokasi maupun lainnya. langsung saja saya jelaskan tahapannya :

1. SDK Android Sudah terinstal
2. Android Studio Sudah wajib terinstal
3. Pastikan ada koneksi internet (modem / wi-fi [disarankan])
4. Buka SDK Android, kemudian Instal Package Google Play Services

Instal Google Play Services


5. Buat Project Baru di android studio, pilih Google Maps Activity

Pilih Google Maps Activity


6. selanjutnya enabling your api, sesuai link yang ada di google_maps_api.xml

Aktifkan APIs sesuai link yang sudah ada


7. create project di API console (https://code.google.com/apis/console)
8. pilih APIs & auth > APIs > Google Maps Android API

Tahap Google Maps Android API


9. pilih APIs & auth > Credentials > Create New Key > Android Key

Create New Key


10. Masukkan SHA1 Fingerprint Package di kotak

Masukkan SHA1 di kotak untuk generate Key APIs

11. muncul tampilan hasil generate APIs key

Hasil Key APIs yang diblok hitam

12. masukkan key ke google_maps_api.xml

Masukkan ke Projects


13. sekarang lanjutkan, membuat MapsActivity.java , kita ambil contoh marker posisi ragunan dan taman mini indah :

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity ex

tends Activity {
static final LatLng RAGUNAN = new LatLng(-6.3039, 106.8267);
static final LatLng TAMANMINI = new LatLng(-6.29436, 106.8859);
private GoogleMap map;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker ragunan = map.addMarker(new MarkerOptions().position(RAGUNAN)
.title(“Ragunan”)
.snippet(“Ragunan”)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.cabin_2)));
Marker tamanmini = map.addMarker(new MarkerOptions()
.position(TAMANMINI)
.title(“Taman Mini”)
.snippet(“Taman Mini itu Indah”)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.cabin_2)));
// Move the camera instantly to hamburg with a zoom of 15. map.moveCamera(CameraUpdateFactory.newLatLngZoom(RAGUNAN, 15));
// Zoom in, animating the camera. map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

14. buat activity_maps.xml :

<RelativeLayout 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” tools:context=“.MapsActivity” >
<fragment android:id=“@+id/map” android:layout_width=“match_parent” android:layout_height=“match_parent” class=“com.google.android.gms.maps.MapFragment” android:layout_margin=“20dp” />
</RelativeLayout>

15. buat file appsrcdebugresvaluesgoogle_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=64:03:25:62:EC:CA:5D:5A:29:7D:AA:3F:B6:91:96:20:F5:47:08:16%3Bcom.andhika.pakdh_000.ujipeta
You can also add your credentials to an existing key, using this line: 64:03:25:62:EC:CA:5D:5A:29:7D:AA:3F:B6:91:96:20:F5:47:08:16;com.andhika.pakdh_000.ujipeta
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”>
enter key disini
</string>
</resources>


16. Lengkapi android manifest seperti berikut :

<?xml version=“1.0” encoding=“utf-8”?><manifest xmlns:android=“http://schemas.android.com/apk/res/android” package=“com.andhika.pakdh_000.ujipeta” >
<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” />
<uses-permission android:name=“com.google.android.providers.gsf.permission.READ_GSERVICES” />
<!– The ACCESS_COARSE/FINE_LOCATION permissions are not required to use Google Maps Android API v2, but are recommended. –> <uses-permission android:name=“android.permission.ACCESS_COARSE_LOCATION” />
<uses-permission android:name=“android.permission.ACCESS_FINE_LOCATION” />
<uses-permission android:name=“com.andhika.pakdh_000.ujipeta.permission.MAPS_RECEIVE” /> <permission android:name=“com.andhika.pakdh_000.ujipeta.permission.MAPS_RECEIVE” android:protectionLevel=“signature” />
<uses-feature android:glEsVersion=“0x00020000” android:required=“true” />
<application android:allowBackup=“true” android:icon=“@mipmap/ic_launcher” android:label=“@string/app_name” android:theme=“@style/AppTheme” >
<meta-data android:name=“com.google.android.gms.version” android:value=“@integer/google_play_services_version” />
<meta-data android:name=“com.google.android.maps.v2.API_KEY” android:value=“@string/google_maps_key” />
<activity android:name=“.MapsActivity” android:label=“@string/title_activity_maps” >
<intent-filter>
<action android:name=“android.intent.action.MAIN” />
<category android:name=“android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>
</manifest>

17. jalankan project. dan hasilnya :

Hasil Run Device Andromax C2

selamat mencoba

Gravatar Image
Suka jalan-jalan, naik sepeda, bermain code-code asal tidak suka mengkode cinta. Hubungi email : andhika.na@gmail.com jika anda butuh website untuk personal maupun bisnis.

2 thoughts on “Tutorial Menampilkan Google Map Android API v2 di Android Studio

  1. Pengen yang lebih seru …
    Ayo kunjungi http://www.asianbet77.com
    Buktikan sendiri ..

    Real Play = Real Money

    – Bonus Promo Red Card pertandingan manapun .
    – Bonus Mixparlay .
    – Bonus Tangkasnet setiap hari .
    – New Produk Sabung Ayam ( minimal bet sangat ringan ) .
    – Referal 5 + 1 % ( seumur hidup ) .
    – Cash Back up to 10 % .
    – Bonus Royalty Rewards setiap bulan .

    untuk Informasi lebih jelasnya silahkan hubungi CS kami :
    – YM : op1_asianbet77@yahoo.com
    – EMAIL : asianbet77@yahoo.com
    – WHATSAPP : +63 905 213 7234
    – WECHAT : asianbet_77
    – SMS CENTER : +63 905 209 8162
    – PIN BB : 2B4BB06A / 28339A41

    Salam Admin ,
    http://asianbet77.com/

  2. gan yang bagian

    @Override public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }

    yang menu setelah R'nya kok masih error ya ?

Leave a Reply

Your email address will not be published. Required fields are marked *