Lesson 9
Android Apps Coding – Part 2
Abdulrahman Ahmed
PhD IT(Currently), MSc. IT, MSc. CS & BSc. IT
CONTENT
Android Google Map
Android Popup Menu
1. Android Google Map
Exercise 1
Android Google Map
Android provides facility to integrate Google map in our
application.
Google map displays your current location, navigate location
direction, search location etc. We can also customize Google
map according to our requirement.
Types of Google Maps
There are four different types of Google maps, as well as an
optional to no map at all.
Each of them gives different view on map.
These maps are as follow:
1. Normal
This type of map displays typical road map, natural features
like river and some features build by humans.
Exercise 1
Android Google Map
2. Hybrid
This type of map displays satellite photograph data with
typical road maps.
It also displays road and feature labels.
3. Satellite
Satellite type displays satellite photograph data, but doesn't
display road and feature labels.
4. Terrain
This type displays photographic data.
This includes colors, contour lines and labels and perspective
shading.
5. None
This type displays an empty grid with no tiles loaded.
Exercise 1
Android Google Map
Syntax of different types of map
Exercise 1
Android Google Map
Methods of Google map
Google map API provides several methods that help to customize Google map.
These methods are as following:
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
For doing this we select Google Maps Activity.
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
Copy the URL from google_map_api.xml file to generate Google map key.
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
Paste the copied URL at the browser.
It will open the following page.
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
After clicking on Create API key
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
Then it will generate our API key displaying the following screen.
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
Copy this generated API key in our google_map_api.xml file
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
1. Activity_maps.xml
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
To get the GoogleMap object in our MapsActivity.java class we need to implement the
OnMapReadyCallback interface and override the onMapReady() callback method.
2. MapsActivity.java
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
Required Permission: Add the following user-permission in AndroidManifest.xml
3. AndroidManifest.xml
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
Build.gradel: Add the following dependencies in build.gradel file.
4. build.gradel
Exercise 1
Android Google Map
Let's create an example of Google map integrating within our app.
5. Output
2. Android Popup Menu
Exercise 2
Android Popup Menu
Android Popup Menu displays the menu below the anchor
text if space is available otherwise above the anchor text.
It disappears if you click outside the popup menu.
The android.widget.PopupMenu is the direct subclass of
java.lang.Object class.
Let's see how to create popup menu in android.
1. Activity_main.xml
It contains only one button.
Exercise 2
Android Popup Menu
1. Activity_main.xml
Exercise 2
Android Popup Menu
It contains three items as show below. It is created inside the
res/menu directory.
2. Popup_menu.xml
Exercise 2
Android Popup Menu
It displays the popup menu on button click.
3. Class Activity
Exercise 2
Android Popup Menu
It displays the popup menu on button click.
4. Output
Next Session
Android Apps Coding – Part 3
Make Phone Call Coding
Send SMS Coding
The End
Any Questions?