SlideShare une entreprise Scribd logo
1  sur  22
Android Application Development Google Map View Ahsanul Karim ahsanul.karim@sentinelbd.com Sentinel Solutions Ltd. http://www.sentinelbd.com
Google Map View Using the Google Maps library, we can create our own map-viewing Activity Our simple map application will have 2 parts: We show a map where user can move and zoom We’ll add overlay items to show points of interest Prerequisites: External Google Maps library installed in your SDK environment.  The Maps library is included with the Google APIs add-on,  which you can install using the Android SDK and AVD Manager. Map API KEY Set up a new AVD that uses the same Google APIs deployment  target
Google Map View Advantages of using MapView and MapActivity Integrate Google maps in application easily It provides built-in map downloading, rendering, and caching of Maps tiles Provides variety of display options and controls provides a wrapper around the Google Maps API that lets your application request and manipulate Google Maps data through class methods, and it lets you work with Maps data as you would other types of Views.
Google Map View Part 1: Creating a Map Activity Create a project HelloGoogleMaps Using Google APIs Using Google APIs the default.propertiesfile:
Google Map View Part 1: Creating a Map Activity (Contd.) 2. Because the Maps library is not a part of the standard Android library, we must declare it in the Android Manifest. Open the AndroidManifest.xml file and add the following  as a child of the <application> element 3. Add INTERNET permission too
Google Map View Part 1: Creating a Map Activity (Contd.) 4. Open the res/layout/main.xml file and add a single com.google.android.maps.MapView as the root node: Now we’ll have to obtain the Maps API key 5. Now open the HelloGoogleMaps.java file. For this Activity, extend MapActivity  (instead of Activity) 6. Inside every MapActivity, the isRouteDisplayed() method is required, so we override  This method So HelloGoogleMaps.java looks like:
Google Map View Part 1: Creating a Map Activity (Contd.) HelloGoogleMaps.java isRouteDisplayed() is required for some accounting from the Maps service to see if we are  currently displaying any route information. In this case, we are not, so return false.
Google Map View Part 1: Creating a Map Activity (Contd.) 6. This loads the layout file created above. We add built in zoom option with  setBuiltInZoomControls(boolean). Do this at the end of the onCreate() method:
Google Map View Part 1: Creating a Map Activity (Contd.) 7. Now we create AVD using Google APIs and run The Map won’t display without the proper MAP API KEY
Google Map View Obtaining a Maps API Key MapView gives access to Google Maps data, so need to register with the Google Maps service  and agree to the applicable Terms of Service before your MapView will be able to obtain data  from Google Maps. This will apply whether you are developing your application on the  emulator or preparing your application for deployment to mobile devices. Registering for a Maps API Key is simple, free, and has two parts: Registering the MD5 fingerprint of the certificate that you will use to sign your application.  The Maps registration service then provides you a Maps API Key that is associated with  your application's signer certificate. Adding a reference to the Maps API Key in each MapView, whether declared in XML or  instantiated directly from code. You can use the same Maps API Key for any MapView in  any Android application, provided that the application is signed with the certificate  whose fingerprint you registered with the service. We’ll use debug certificate here
Google Map View Obtaining a Maps API Key (Contd.) 1. MD5 fingerprint of the debug certificate By default, build tools create the debug keystore in the active AVD directory. The location of the AVD directories varies by platform: Windows Vista: C:serslt;user>androidebug.keystore Windows XP: C:ocuments and Settingslt;user>androidebug.keystore   We can Windows > Prefs > Android > Build to check the full path, which you can then paste    into a file explorer to locate the directory containing the keystore.
Google Map View Obtaining a Maps API Key (Contd.) 1. MD5 fingerprint of the debug certificate (Contd.) 3. Once you have located the keystore, use this Keytool command to get the MD5 fingerprint  of the debug certificate: Open command prompt and go to JAVA_Path/bin/ folder. This folder contains keytools We write the command: keytool  -list   -alias  androiddebugkey    -keystore<path_to_debug_keystore>.keystore -storepass    android       -keypass     android
Google Map View Obtaining a Maps API Key (Contd.) 1. MD5 fingerprint of the debug certificate (Contd.) keytool  -list   -alias  androiddebugkey    -keystore<path_to_debug_keystore>.keystore -storepass    android       -keypass     android Using the command we get MD5 finger print MD5 fingerprint:  5D:4E:16:49:FD:8C:D3:BD:F4:31:BA:A7:B5:5C:2C:DC
Google Map View Obtaining a Maps API Key (Contd.) 1. Registering the Certificate Fingerprint with the Google Maps Service For a Maps API Key, load this page in a browser: http://code.google. com/android/maps-api-signup.html We get the screen:
Google Map View Obtaining a Maps API Key (Contd.) 1. Registering the Certificate Fingerprint with the Google Maps Service Now we get Now, we place the api key in main.xml  and run the app again
Google Map View Part 1: Creating a Map Activity (Contd.)
Google Map View Part 2: Adding Overlay Items Now we’ll position overlay items and markers Create a new Java class named HelloItemizedOverlay that implements ItemizedOverlay. When using Eclipse, right-click the package name in the Eclipse Package Explorer, and select  New > Class. Fill-in the Name field as HelloItemizedOverlay. 2. First, you need an OverlayItem ArrayList, in which you'll put each of the OverlayItem  objects you want on the map. Add this at the top of the HelloItemizedOverlay class 3. Now define the HelloItemizedOverlay constructors. The constructor must define the  default marker for each of the OverlayItems. In order for the Drawable to actually get drawn,  it must have its bounds defined. Most commonly, you want the center-point at the bottom  of the image to be the point at which it's attached to the map coordinates.  This is handled for you with the boundCenterBottom() method. Wrap this around our  defaultMarker
Google Map View Part 2: Adding Overlay Items
Google Map View Part 2: Adding Overlay Items Now we’ll position overlay items and markers 4. In order to add new OverlayItems to the ArrayList, you need a new method: Each time you add a new OverlayItem to the ArrayList, you must call populate() for the  ItemizedOverlay, which will read each of the OverlayItems and prepare them to be drawn. When the populate() method executes, it will call createItem(int) in the ItemizedOverlay  to retrieve each OverlayItem. 5. Then override the onTap(int) callback method, which will handle the event when an item  is tapped by the user:
Google Map View Part 2: Adding Overlay Items Now we use HelloItemizedOverlay 1. At the end of your existing onCreate() method, instantiate : All overlay elements on a map are held by the MapView, so when you want to add some,  have to get a list from the getOverlays() method. Then instantiate the Drawable used for the  map marker, which was saved in the res/drawable/ directory.  2. Now create a GeoPoint that defines the map coordinates for the first overlay item,  and pass it to a new OverlayItem: GeoPoint coordinates are specified in microdegrees (degrees * 1e6).  The OverlayItem constructor accepts the GeoPoint location, a string for the item's title, and  a string for the item's snippet text, 3. All that's left is to add this OverlayItem to your collection in the HelloItemizedOverlay  instance, then add the HelloItemizedOverlay to the MapView
Google Map View Part 2: Adding Overlay Items We can add more geopoints here We can take these points from location listeners
Google Map View

Contenu connexe

Tendances

Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming BasicsEueung Mulyana
 
Activities, Fragments, and Events
Activities, Fragments, and EventsActivities, Fragments, and Events
Activities, Fragments, and EventsHenry Osborne
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and DesignHaitham El-Ghareeb
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application FrameworkYong Heui Cho
 
Layouts in android
Layouts in androidLayouts in android
Layouts in androidDurai S
 
Message passing ( in computer science)
Message   passing  ( in   computer  science)Message   passing  ( in   computer  science)
Message passing ( in computer science)Computer_ at_home
 
Screen orientations in android
Screen orientations in androidScreen orientations in android
Screen orientations in androidmanjakannar
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.netDeep Patel
 
2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software conceptsPrajakta Rane
 
Android resource
Android resourceAndroid resource
Android resourceKrazy Koder
 
Android ui dialog
Android ui dialogAndroid ui dialog
Android ui dialogKrazy Koder
 
14. session 14 dhtml filter
14. session 14   dhtml filter14. session 14   dhtml filter
14. session 14 dhtml filterPhúc Đỗ
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in androidPrawesh Shrestha
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Developmentdonnfelker
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure callSunita Sahu
 
Back face detection
Back face detectionBack face detection
Back face detectionPooja Dixit
 

Tendances (20)

Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
Fragment
Fragment Fragment
Fragment
 
Activities, Fragments, and Events
Activities, Fragments, and EventsActivities, Fragments, and Events
Activities, Fragments, and Events
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
 
Asp.net file types
Asp.net file typesAsp.net file types
Asp.net file types
 
Android - Android Geocoding and Location based Services
Android - Android Geocoding and Location based ServicesAndroid - Android Geocoding and Location based Services
Android - Android Geocoding and Location based Services
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
Web services SOAP
Web services SOAPWeb services SOAP
Web services SOAP
 
Message passing ( in computer science)
Message   passing  ( in   computer  science)Message   passing  ( in   computer  science)
Message passing ( in computer science)
 
Screen orientations in android
Screen orientations in androidScreen orientations in android
Screen orientations in android
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.net
 
2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts
 
Android resource
Android resourceAndroid resource
Android resource
 
Android ui dialog
Android ui dialogAndroid ui dialog
Android ui dialog
 
14. session 14 dhtml filter
14. session 14   dhtml filter14. session 14   dhtml filter
14. session 14 dhtml filter
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 
Back face detection
Back face detectionBack face detection
Back face detection
 

En vedette

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 studioParinita03
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentAhsanul Karim
 
Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)Ahsanul Karim
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAhsanul Karim
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIAhsanul Karim
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesAhsanul Karim
 
Android before getting started
Android before getting startedAndroid before getting started
Android before getting startedAhsanul Karim
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)Ahsanul Karim
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedAhsanul Karim
 
Day: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentDay: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentAhsanul Karim
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in BackgroundAhsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Lecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewLecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewAhsanul Karim
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedAhsanul Karim
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities Ahsanul Karim
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerAhsanul Karim
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_startedAhsanul Karim
 

En vedette (20)

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
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver Component
 
Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form Widgets
 
Android Services
Android ServicesAndroid Services
Android Services
 
Training android
Training androidTraining android
Training android
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts API
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & Preferences
 
Client-Server
Client-ServerClient-Server
Client-Server
 
Android before getting started
Android before getting startedAndroid before getting started
Android before getting started
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting Started
 
Day: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentDay: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application Development
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
Lecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewLecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick Overview
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting Started
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation Primer
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
 

Similaire à Android MapView and MapActivity

Android chapter25-map views
Android chapter25-map viewsAndroid chapter25-map views
Android chapter25-map viewsTran Le Hoan
 
Maps API on_mobile_dev_festbangkok
Maps API on_mobile_dev_festbangkokMaps API on_mobile_dev_festbangkok
Maps API on_mobile_dev_festbangkokss318
 
Android mobile application for gps
Android mobile application for gpsAndroid mobile application for gps
Android mobile application for gpsSutej Chakka
 
Android application for gps
Android application for gpsAndroid application for gps
Android application for gpsSutej Chakka
 
Location based services 10
Location based services   10Location based services   10
Location based services 10Michael Shrove
 
Angular google maps tutorial quick guide
Angular google maps tutorial quick guideAngular google maps tutorial quick guide
Angular google maps tutorial quick guideKaty Slemon
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentIJERD Editor
 
Holland9 Android Workshop Hogeschool Rotterdam
Holland9 Android Workshop Hogeschool RotterdamHolland9 Android Workshop Hogeschool Rotterdam
Holland9 Android Workshop Hogeschool RotterdamJ B
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorialkatayoon_bz
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorialEd Zel
 
Google Location Services
Google Location ServicesGoogle Location Services
Google Location ServicesVishal Sapariya
 

Similaire à Android MapView and MapActivity (20)

Android chapter25-map views
Android chapter25-map viewsAndroid chapter25-map views
Android chapter25-map views
 
Intro To Google Maps
Intro To Google MapsIntro To Google Maps
Intro To Google Maps
 
Google Map Code
Google Map CodeGoogle Map Code
Google Map Code
 
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
 
Map
MapMap
Map
 
Maps API on_mobile_dev_festbangkok
Maps API on_mobile_dev_festbangkokMaps API on_mobile_dev_festbangkok
Maps API on_mobile_dev_festbangkok
 
MAD Unit 6.pptx
MAD Unit 6.pptxMAD Unit 6.pptx
MAD Unit 6.pptx
 
Android mobile application for gps
Android mobile application for gpsAndroid mobile application for gps
Android mobile application for gps
 
Android application for gps
Android application for gpsAndroid application for gps
Android application for gps
 
Location based services 10
Location based services   10Location based services   10
Location based services 10
 
Angular google maps tutorial quick guide
Angular google maps tutorial quick guideAngular google maps tutorial quick guide
Angular google maps tutorial quick guide
 
@Ionic native/google-maps
@Ionic native/google-maps@Ionic native/google-maps
@Ionic native/google-maps
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and Development
 
Android
AndroidAndroid
Android
 
Holland9 Android Workshop Hogeschool Rotterdam
Holland9 Android Workshop Hogeschool RotterdamHolland9 Android Workshop Hogeschool Rotterdam
Holland9 Android Workshop Hogeschool Rotterdam
 
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
 
Google Location Services
Google Location ServicesGoogle Location Services
Google Location Services
 

Plus de Ahsanul Karim

Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedAhsanul Karim
 
লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:Ahsanul Karim
 
Day 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIDay 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIAhsanul Karim
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsAhsanul Karim
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsAhsanul Karim
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Ahsanul Karim
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycleAhsanul Karim
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI WidgetsAhsanul Karim
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesAhsanul Karim
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overviewAhsanul Karim
 
Mobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyMobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyAhsanul Karim
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorialAhsanul Karim
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Ahsanul Karim
 
Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Ahsanul Karim
 

Plus de Ahsanul Karim (17)

Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting Started
 
লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:
 
Day 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIDay 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location API
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overview
 
Mobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyMobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete Study
 
GCM for Android
GCM for AndroidGCM for Android
GCM for Android
 
List Views
List ViewsList Views
List Views
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorial
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
 
Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2
 
Android 1.8 sensor
Android 1.8 sensorAndroid 1.8 sensor
Android 1.8 sensor
 

Dernier

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Dernier (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

Android MapView and MapActivity

  • 1. Android Application Development Google Map View Ahsanul Karim ahsanul.karim@sentinelbd.com Sentinel Solutions Ltd. http://www.sentinelbd.com
  • 2. Google Map View Using the Google Maps library, we can create our own map-viewing Activity Our simple map application will have 2 parts: We show a map where user can move and zoom We’ll add overlay items to show points of interest Prerequisites: External Google Maps library installed in your SDK environment. The Maps library is included with the Google APIs add-on, which you can install using the Android SDK and AVD Manager. Map API KEY Set up a new AVD that uses the same Google APIs deployment target
  • 3. Google Map View Advantages of using MapView and MapActivity Integrate Google maps in application easily It provides built-in map downloading, rendering, and caching of Maps tiles Provides variety of display options and controls provides a wrapper around the Google Maps API that lets your application request and manipulate Google Maps data through class methods, and it lets you work with Maps data as you would other types of Views.
  • 4. Google Map View Part 1: Creating a Map Activity Create a project HelloGoogleMaps Using Google APIs Using Google APIs the default.propertiesfile:
  • 5. Google Map View Part 1: Creating a Map Activity (Contd.) 2. Because the Maps library is not a part of the standard Android library, we must declare it in the Android Manifest. Open the AndroidManifest.xml file and add the following as a child of the <application> element 3. Add INTERNET permission too
  • 6. Google Map View Part 1: Creating a Map Activity (Contd.) 4. Open the res/layout/main.xml file and add a single com.google.android.maps.MapView as the root node: Now we’ll have to obtain the Maps API key 5. Now open the HelloGoogleMaps.java file. For this Activity, extend MapActivity  (instead of Activity) 6. Inside every MapActivity, the isRouteDisplayed() method is required, so we override This method So HelloGoogleMaps.java looks like:
  • 7. Google Map View Part 1: Creating a Map Activity (Contd.) HelloGoogleMaps.java isRouteDisplayed() is required for some accounting from the Maps service to see if we are currently displaying any route information. In this case, we are not, so return false.
  • 8. Google Map View Part 1: Creating a Map Activity (Contd.) 6. This loads the layout file created above. We add built in zoom option with  setBuiltInZoomControls(boolean). Do this at the end of the onCreate() method:
  • 9. Google Map View Part 1: Creating a Map Activity (Contd.) 7. Now we create AVD using Google APIs and run The Map won’t display without the proper MAP API KEY
  • 10. Google Map View Obtaining a Maps API Key MapView gives access to Google Maps data, so need to register with the Google Maps service and agree to the applicable Terms of Service before your MapView will be able to obtain data from Google Maps. This will apply whether you are developing your application on the emulator or preparing your application for deployment to mobile devices. Registering for a Maps API Key is simple, free, and has two parts: Registering the MD5 fingerprint of the certificate that you will use to sign your application. The Maps registration service then provides you a Maps API Key that is associated with your application's signer certificate. Adding a reference to the Maps API Key in each MapView, whether declared in XML or instantiated directly from code. You can use the same Maps API Key for any MapView in any Android application, provided that the application is signed with the certificate whose fingerprint you registered with the service. We’ll use debug certificate here
  • 11. Google Map View Obtaining a Maps API Key (Contd.) 1. MD5 fingerprint of the debug certificate By default, build tools create the debug keystore in the active AVD directory. The location of the AVD directories varies by platform: Windows Vista: C:serslt;user>androidebug.keystore Windows XP: C:ocuments and Settingslt;user>androidebug.keystore We can Windows > Prefs > Android > Build to check the full path, which you can then paste into a file explorer to locate the directory containing the keystore.
  • 12. Google Map View Obtaining a Maps API Key (Contd.) 1. MD5 fingerprint of the debug certificate (Contd.) 3. Once you have located the keystore, use this Keytool command to get the MD5 fingerprint of the debug certificate: Open command prompt and go to JAVA_Path/bin/ folder. This folder contains keytools We write the command: keytool -list -alias androiddebugkey -keystore<path_to_debug_keystore>.keystore -storepass android -keypass android
  • 13. Google Map View Obtaining a Maps API Key (Contd.) 1. MD5 fingerprint of the debug certificate (Contd.) keytool -list -alias androiddebugkey -keystore<path_to_debug_keystore>.keystore -storepass android -keypass android Using the command we get MD5 finger print MD5 fingerprint: 5D:4E:16:49:FD:8C:D3:BD:F4:31:BA:A7:B5:5C:2C:DC
  • 14. Google Map View Obtaining a Maps API Key (Contd.) 1. Registering the Certificate Fingerprint with the Google Maps Service For a Maps API Key, load this page in a browser: http://code.google. com/android/maps-api-signup.html We get the screen:
  • 15. Google Map View Obtaining a Maps API Key (Contd.) 1. Registering the Certificate Fingerprint with the Google Maps Service Now we get Now, we place the api key in main.xml and run the app again
  • 16. Google Map View Part 1: Creating a Map Activity (Contd.)
  • 17. Google Map View Part 2: Adding Overlay Items Now we’ll position overlay items and markers Create a new Java class named HelloItemizedOverlay that implements ItemizedOverlay. When using Eclipse, right-click the package name in the Eclipse Package Explorer, and select  New > Class. Fill-in the Name field as HelloItemizedOverlay. 2. First, you need an OverlayItem ArrayList, in which you'll put each of the OverlayItem  objects you want on the map. Add this at the top of the HelloItemizedOverlay class 3. Now define the HelloItemizedOverlay constructors. The constructor must define the default marker for each of the OverlayItems. In order for the Drawable to actually get drawn, it must have its bounds defined. Most commonly, you want the center-point at the bottom of the image to be the point at which it's attached to the map coordinates. This is handled for you with the boundCenterBottom() method. Wrap this around our defaultMarker
  • 18. Google Map View Part 2: Adding Overlay Items
  • 19. Google Map View Part 2: Adding Overlay Items Now we’ll position overlay items and markers 4. In order to add new OverlayItems to the ArrayList, you need a new method: Each time you add a new OverlayItem to the ArrayList, you must call populate() for the  ItemizedOverlay, which will read each of the OverlayItems and prepare them to be drawn. When the populate() method executes, it will call createItem(int) in the ItemizedOverlay  to retrieve each OverlayItem. 5. Then override the onTap(int) callback method, which will handle the event when an item is tapped by the user:
  • 20. Google Map View Part 2: Adding Overlay Items Now we use HelloItemizedOverlay 1. At the end of your existing onCreate() method, instantiate : All overlay elements on a map are held by the MapView, so when you want to add some, have to get a list from the getOverlays() method. Then instantiate the Drawable used for the map marker, which was saved in the res/drawable/ directory. 2. Now create a GeoPoint that defines the map coordinates for the first overlay item, and pass it to a new OverlayItem: GeoPoint coordinates are specified in microdegrees (degrees * 1e6). The OverlayItem constructor accepts the GeoPoint location, a string for the item's title, and a string for the item's snippet text, 3. All that's left is to add this OverlayItem to your collection in the HelloItemizedOverlay  instance, then add the HelloItemizedOverlay to the MapView
  • 21. Google Map View Part 2: Adding Overlay Items We can add more geopoints here We can take these points from location listeners