Skip to content Skip to sidebar Skip to footer

Tutorial on Creating a Mobile GIS Application Using Android Studio: Creating a Google Maps Activity [Bagian 5]

After creating the main menu in the previous tutorial, in this tutorial the author will create an activity for maps. For those who are new to this tutorial, you can follow the project from the beginning by looking at the previous tutorial:

The following are the steps to create a google maps activity on android studio:

1. Open android project, right click on app > new > google > google maps activity as follows :

2. Next will appear window as follows :

Let Activity name and layout name default as above, then select finish.

3. Then an activity and layout will be formed for maps. On value > google_maps_api.xml fill in the API KEY that was obtained in the tutorial part 3. Fill it as in the red section below:

4. Then on MainActivity.java add command Intent on the image with the id “mapsBtn” so that when the image is clicked or selected by user then it will do the intent command to move activity to MapsActivity.java. Add command inside onCreate as follows :

ImageView mapsBtn = (ImageView) findViewById(R.id.mapsBtn);mapsBtn.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View v) {        Intent i = new Intent(MainActivity.this, MapsActivity.class);        startActivity(i);    }});

5. If it has been added and it doesn’t exist errordo running project. If successful then the application will display first splash screen activities, then Activity Main Menu, and when selected image (which is used as a map button) is selected it will open activity maps as follows :

Thus the google maps activity has been successfully added to the project. By adding activity maps, the activity for maps will be automatically registered in the manifest as shown below: