SlideShare a Scribd company logo
Chapter-6
Notes By Mr. C. P.Divate
Location Based Services
Android Google Maps API with Examples
By using Google Maps Android API we can integrate google maps in android applications to show
the location details on map based on our requirements.
To use google maps in our android applications we need to install Google Play Services SDK in
our Android Studio because google made Google Mas API as a part of Google Play Services SDK.
To install Google Play Services, open Android Studio  Go to Tools menu  Android  click SDK
Manager, then new window will open in that select SDK Tools tab  Select Google Play
Services  click OK like as shown below.
Once we are done with Google Play Services installation in android studio, now we will see how to
integrate google map in android app with examples.
Android Google Maps API Example
Following is the example of adding or integrating a google map in android application.
Create a new android application using android studio and give names as GoogleMapExample like
as shown below.
Now we need to select the form factors which we need for our app. In case if you're not sure what
you need, just select Phone and Tablet and then click Next like as shown below.
Now select the Google Maps Activity in 'Add an activity to Mobile' dialog and click Next like as
shown below.
Customize the activity by entering activity name, layout name and title as prompted. In case if default
values are fine, then click Finish like as shown below.
Once the project created, Android Studio will
open google_maps_api.xml and MapsActivity.java files in the editor.
The google_maps_api.xml file will contains instructions to generate a Google Maps API key to
access Google Maps servers. Copy the link provided in the google_maps_api.xml file like as shown
below.
Create a Project in Google Console
Copy and paste the console URL in browser and it will take you to Google API Console like as
shown below. Follow the instructions to create a new project on Google API Console like as shown
below.
Once we click on continue it will create a project and Google Maps Android API will be enabled.
Now we need to create an API key to call the API for that click on Create API Key like as shown
below.
Once we click on Create API Key, it will create an API key to use it in our applications like as shown
below.
Now copy the API Key, go back to android studio and paste the API key into the <string> element
in google_maps_api.xml file like as shown below.
<string name="google_maps_key" templateMergeStrategy="preserve" translatab
le="false">AIzaSyCKPTaBv41DKqr9qxMPWOQAsqp0Q4NHMER</string>
Activity_maps.xml
By default, the XML file (activity_maps.xml) that defines the app's layout is at res/layout/ contains
the following code.
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tutlane.googlemapexample.MapsActivity" />
AndroidManifest.xml
Our application manifest file (AndroidManifest.xml) will contain the code like as shown below with
required our Google Maps API Key and permissions.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tutlane.googlemapexample">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION
" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.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>
If you observe above code it contains a user permission to access location and Meta tag to get
google maps API key.
MapsActivity.java
By default, the Java file (MapsActivity.java) that defines the maps activity will contain the following
code.
package com.tutlane.googlemapexample;
import android.support.v4.app.FragmentActivity;
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;
public class MapsActivity extends FragmentActivity implements OnMapReadyCa
llback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is
ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFr
agmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in hyderabad and move the camera
LatLng hyderadbad = new LatLng(17, 78);
mMap.addMarker(new MarkerOptions().position(hyderadbad).title("Tut
lane in India"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(hyderadbad));
}
}
Generally, during the launch of our activity, onCreate() callback method will be called by android
framework to get the required layout for an activity.
Output of Android Google Maps Example
When we run the above example using an android virtual device (AVD) we will get a result like as
shown below.
If you observe above result, we are able to see a map with a marker positioned over Hyderabad,
India in our application.
We can customize the appearance of a map based on our requirements in the android application.
Android Google Map Types
The Google Maps Android API provides a map in different types such as Normal, Hybrid, Satellite,
Terrain and None.
Map
Type Description
Normal Typical road map. Shows roads, some features built by humans, and important natural features li
Map
Type Description
rivers. Road and feature labels are also visible.
Hybrid Satellite photograph data with road maps added. Road and feature labels are also visible.
Satellite Satellite photograph data. Road and feature labels are not visible.
Terrian Topographic data. The map includes colors, contour lines and labels, and perspective shading. Som
roads and labels are also visible.
None No tiles. The map will be rendered as an empty grid with no tiles loaded.
In android, we can change the type of a map by calling the GoogleMap
object’s setMapType() method, by passing the type of constants defined in GoogleMap.
Following is the example of displaying the map type as Satellite in the android application.
GoogleMap map;
......
// Set Map type as Satellite
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
// Same way we can set other type maps also like as below.
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
map.setMapType(GoogleMap.MAP_TYPE_NONE);
This is how we can add or integrate google maps in android applications and use different map
types based on our requirements.

More Related Content

Similar to Location Based Services Android Google Maps API with Examples

Intro To Google Maps
Intro To Google MapsIntro To Google Maps
Intro To Google Maps
Eric ShangKuan
 
Code to Add Google Map to Websites
Code to Add Google Map to WebsitesCode to Add Google Map to Websites
Code to Add Google Map to Websites
Fortune Innovations Dublin
 
Android ui with xml
Android ui with xmlAndroid ui with xml
Android ui with xml
Egerton University
 
Android app development guide for freshers by ace web academy
Android app development guide for freshers  by ace web academyAndroid app development guide for freshers  by ace web academy
Android app development guide for freshers by ace web academy
Ace Web Academy -Career Development Center
 
Angular google maps tutorial quick guide
Angular google maps tutorial quick guideAngular google maps tutorial quick guide
Angular google maps tutorial quick guide
Katy Slemon
 
Android Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdfAndroid Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdf
SudhanshiBakre1
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
Gil Irizarry
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
Parinita03
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
Techacademy Software
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
Ed Zel
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
katayoon_bz
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
Keshav Chauhan
 
Geekcamp Android
Geekcamp AndroidGeekcamp Android
Geekcamp Android
Hean Hong Leong
 
android level 3
android level 3android level 3
android level 3
DevMix
 
Android-Tutorial.ppt
Android-Tutorial.pptAndroid-Tutorial.ppt
Android-Tutorial.ppt
siddharthsingh496426
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
Avinash Nandakumar
 
How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
InnovationM
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
Alberto Jr Gaudicos
 
Unit5 Mobile Application Development.doc
Unit5 Mobile Application Development.docUnit5 Mobile Application Development.doc
Unit5 Mobile Application Development.doc
KNANTHINIMCA
 
Ap quiz app
Ap quiz appAp quiz app
Ap quiz app
angelicaurio
 

Similar to Location Based Services Android Google Maps API with Examples (20)

Intro To Google Maps
Intro To Google MapsIntro To Google Maps
Intro To Google Maps
 
Code to Add Google Map to Websites
Code to Add Google Map to WebsitesCode to Add Google Map to Websites
Code to Add Google Map to Websites
 
Android ui with xml
Android ui with xmlAndroid ui with xml
Android ui with xml
 
Android app development guide for freshers by ace web academy
Android app development guide for freshers  by ace web academyAndroid app development guide for freshers  by ace web academy
Android app development guide for freshers by ace web academy
 
Angular google maps tutorial quick guide
Angular google maps tutorial quick guideAngular google maps tutorial quick guide
Angular google maps tutorial quick guide
 
Android Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdfAndroid Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdf
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Geekcamp Android
Geekcamp AndroidGeekcamp Android
Geekcamp Android
 
android level 3
android level 3android level 3
android level 3
 
Android-Tutorial.ppt
Android-Tutorial.pptAndroid-Tutorial.ppt
Android-Tutorial.ppt
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Unit5 Mobile Application Development.doc
Unit5 Mobile Application Development.docUnit5 Mobile Application Development.doc
Unit5 Mobile Application Development.doc
 
Ap quiz app
Ap quiz appAp quiz app
Ap quiz app
 

More from Chandrakant Divate

Web Technology LAB MANUAL for Undergraduate Programs
Web Technology  LAB MANUAL for Undergraduate ProgramsWeb Technology  LAB MANUAL for Undergraduate Programs
Web Technology LAB MANUAL for Undergraduate Programs
Chandrakant Divate
 
UNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the NatureUNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the Nature
Chandrakant Divate
 
Study of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block DiagramStudy of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block Diagram
Chandrakant Divate
 
Computer System Output Devices Peripherals
Computer System Output  Devices PeripheralsComputer System Output  Devices Peripherals
Computer System Output Devices Peripherals
Chandrakant Divate
 
Computer system Input Devices Peripherals
Computer system Input  Devices PeripheralsComputer system Input  Devices Peripherals
Computer system Input Devices Peripherals
Chandrakant Divate
 
Computer system Input and Output Devices
Computer system Input and Output DevicesComputer system Input and Output Devices
Computer system Input and Output Devices
Chandrakant Divate
 
Introduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROMIntroduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROM
Chandrakant Divate
 
Introduction to Computer Hardware Systems
Introduction to Computer Hardware SystemsIntroduction to Computer Hardware Systems
Introduction to Computer Hardware Systems
Chandrakant Divate
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2
Chandrakant Divate
 
Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)
Chandrakant Divate
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
Chandrakant Divate
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
Chandrakant Divate
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
Chandrakant Divate
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
Chandrakant Divate
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of Strings
Chandrakant Divate
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
Chandrakant Divate
 
Features and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for BeginnersFeatures and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for Beginners
Chandrakant Divate
 
Basics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and FlowchartBasics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and Flowchart
Chandrakant Divate
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
Chandrakant Divate
 
Computer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric TransformationsComputer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric Transformations
Chandrakant Divate
 

More from Chandrakant Divate (20)

Web Technology LAB MANUAL for Undergraduate Programs
Web Technology  LAB MANUAL for Undergraduate ProgramsWeb Technology  LAB MANUAL for Undergraduate Programs
Web Technology LAB MANUAL for Undergraduate Programs
 
UNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the NatureUNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the Nature
 
Study of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block DiagramStudy of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block Diagram
 
Computer System Output Devices Peripherals
Computer System Output  Devices PeripheralsComputer System Output  Devices Peripherals
Computer System Output Devices Peripherals
 
Computer system Input Devices Peripherals
Computer system Input  Devices PeripheralsComputer system Input  Devices Peripherals
Computer system Input Devices Peripherals
 
Computer system Input and Output Devices
Computer system Input and Output DevicesComputer system Input and Output Devices
Computer system Input and Output Devices
 
Introduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROMIntroduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROM
 
Introduction to Computer Hardware Systems
Introduction to Computer Hardware SystemsIntroduction to Computer Hardware Systems
Introduction to Computer Hardware Systems
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2
 
Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of Strings
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
Features and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for BeginnersFeatures and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for Beginners
 
Basics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and FlowchartBasics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and Flowchart
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Computer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric TransformationsComputer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric Transformations
 

Location Based Services Android Google Maps API with Examples

  • 1. Chapter-6 Notes By Mr. C. P.Divate Location Based Services Android Google Maps API with Examples By using Google Maps Android API we can integrate google maps in android applications to show the location details on map based on our requirements. To use google maps in our android applications we need to install Google Play Services SDK in our Android Studio because google made Google Mas API as a part of Google Play Services SDK. To install Google Play Services, open Android Studio  Go to Tools menu  Android  click SDK Manager, then new window will open in that select SDK Tools tab  Select Google Play Services  click OK like as shown below.
  • 2. Once we are done with Google Play Services installation in android studio, now we will see how to integrate google map in android app with examples. Android Google Maps API Example Following is the example of adding or integrating a google map in android application. Create a new android application using android studio and give names as GoogleMapExample like as shown below. Now we need to select the form factors which we need for our app. In case if you're not sure what you need, just select Phone and Tablet and then click Next like as shown below.
  • 3. Now select the Google Maps Activity in 'Add an activity to Mobile' dialog and click Next like as shown below.
  • 4. Customize the activity by entering activity name, layout name and title as prompted. In case if default values are fine, then click Finish like as shown below.
  • 5. Once the project created, Android Studio will open google_maps_api.xml and MapsActivity.java files in the editor. The google_maps_api.xml file will contains instructions to generate a Google Maps API key to access Google Maps servers. Copy the link provided in the google_maps_api.xml file like as shown below.
  • 6. Create a Project in Google Console Copy and paste the console URL in browser and it will take you to Google API Console like as shown below. Follow the instructions to create a new project on Google API Console like as shown below.
  • 7. Once we click on continue it will create a project and Google Maps Android API will be enabled. Now we need to create an API key to call the API for that click on Create API Key like as shown below. Once we click on Create API Key, it will create an API key to use it in our applications like as shown below. Now copy the API Key, go back to android studio and paste the API key into the <string> element in google_maps_api.xml file like as shown below. <string name="google_maps_key" templateMergeStrategy="preserve" translatab le="false">AIzaSyCKPTaBv41DKqr9qxMPWOQAsqp0Q4NHMER</string> Activity_maps.xml By default, the XML file (activity_maps.xml) that defines the app's layout is at res/layout/ contains the following code.
  • 8. <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.tutlane.googlemapexample.MapsActivity" /> AndroidManifest.xml Our application manifest file (AndroidManifest.xml) will contain the code like as shown below with required our Google Maps API Key and permissions. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tutlane.googlemapexample"> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION " /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <meta-data android:name="com.google.android.geo.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> If you observe above code it contains a user permission to access location and Meta tag to get google maps API key.
  • 9. MapsActivity.java By default, the Java file (MapsActivity.java) that defines the maps activity will contain the following code. package com.tutlane.googlemapexample; import android.support.v4.app.FragmentActivity; 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; public class MapsActivity extends FragmentActivity implements OnMapReadyCa llback { private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFr agmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); } @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; // Add a marker in hyderabad and move the camera LatLng hyderadbad = new LatLng(17, 78); mMap.addMarker(new MarkerOptions().position(hyderadbad).title("Tut lane in India")); mMap.moveCamera(CameraUpdateFactory.newLatLng(hyderadbad)); } } Generally, during the launch of our activity, onCreate() callback method will be called by android framework to get the required layout for an activity. Output of Android Google Maps Example
  • 10. When we run the above example using an android virtual device (AVD) we will get a result like as shown below. If you observe above result, we are able to see a map with a marker positioned over Hyderabad, India in our application. We can customize the appearance of a map based on our requirements in the android application. Android Google Map Types The Google Maps Android API provides a map in different types such as Normal, Hybrid, Satellite, Terrain and None. Map Type Description Normal Typical road map. Shows roads, some features built by humans, and important natural features li
  • 11. Map Type Description rivers. Road and feature labels are also visible. Hybrid Satellite photograph data with road maps added. Road and feature labels are also visible. Satellite Satellite photograph data. Road and feature labels are not visible. Terrian Topographic data. The map includes colors, contour lines and labels, and perspective shading. Som roads and labels are also visible. None No tiles. The map will be rendered as an empty grid with no tiles loaded. In android, we can change the type of a map by calling the GoogleMap object’s setMapType() method, by passing the type of constants defined in GoogleMap. Following is the example of displaying the map type as Satellite in the android application. GoogleMap map; ...... // Set Map type as Satellite map.setMapType(GoogleMap.MAP_TYPE_SATELLITE); // Same way we can set other type maps also like as below. map.setMapType(GoogleMap.MAP_TYPE_NORMAL); map.setMapType(GoogleMap.MAP_TYPE_HYBRID); map.setMapType(GoogleMap.MAP_TYPE_TERRAIN); map.setMapType(GoogleMap.MAP_TYPE_NONE); This is how we can add or integrate google maps in android applications and use different map types based on our requirements.