This tutorial consists of;
- Step 1: In Android Studio ( am using 2.2 ), create a new project with Google Maps activity in it.
- Step 2: The Java code to add.
- Step 3: Handling the MULTIDEX issue.
Incase you’d like to develop an Android apps with the Google Maps activity inside, first you need to acquire the Google Maps API key from the Google API developer console.
Step 1: In Android Studio ( am using 2.2 ), create a new project with Google Maps activity in it.
Choose the Google Maps Activity
You will be displayed with a link in the google_maps_api.xml file. Copy (Ctrl+C) the link till the end of line
Paste (Ctrl+V) on a browser and hit Enter. You will be asked to login to your Google account.
Hit the button Create API key.
Copy the key generated by the Google API developer console. The code starts with Alza…
And back to the Android Studio, paste the API key in the location specified (still in the google_maps_api.xml file).
We’ll discuss later what codes to add to complete the project.
Step 2: The Java code to add.
Open the Java file which has the Maps Activitity, and add the following codes, copy the code after the image.
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in KUIS, Bandar Seri Putra and move the camera
// KUIS 2.8905° N, 101.7885° E
LatLng bsp = new LatLng(2.8905, 101.7885);
mMap.addMarker(new MarkerOptions().position(bsp).title(location));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(bsp)
.zoom(20)
.bearing(70)
.tilt(25)
.build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}//end onMapReady
Step 3: Handling the MULTIDEX issue.
In AndroidManifest.xml
android:name="android.support.multidex.MultiDexApplication"
In build.gradle add these two lines;
multiDexEnabled true //// ADD Enabling multidex support
compile 'com.android.support:multidex:1.0.0' // ADD Enabling multidex support
And hit Sync Now
After finishing the Gradle sync, run and test in a real device. Emulator will not display the maps with the default setting.
Need face-to-face lesson?, we also provide Android Studio training, 0129034614
http://bit.ly/androidjsk
This tutorial is developing, bookmark or like below to follow…
SHARE to your friends...
Comments
Post a Comment