SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

Software Risk Management
Software Risk ManagementSoftware Risk Management
Software Risk Management
Gunjan Patel
 

La actualidad más candente (20)

Android architecture
Android architectureAndroid architecture
Android architecture
 
Designing applications with multimedia capabilities
Designing applications with multimedia capabilitiesDesigning applications with multimedia capabilities
Designing applications with multimedia capabilities
 
Python ppt
Python pptPython ppt
Python ppt
 
Requirement specification (SRS)
Requirement specification (SRS)Requirement specification (SRS)
Requirement specification (SRS)
 
Chat Application
Chat ApplicationChat Application
Chat Application
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 
Software Risk Management
Software Risk ManagementSoftware Risk Management
Software Risk Management
 
Project Planning in Software Engineering
Project Planning in Software EngineeringProject Planning in Software Engineering
Project Planning in Software Engineering
 
State chart diagram
State chart diagramState chart diagram
State chart diagram
 
Introduction to Android ppt
Introduction to Android pptIntroduction to Android ppt
Introduction to Android ppt
 
Mobile Information Architecture
Mobile Information ArchitectureMobile Information Architecture
Mobile Information Architecture
 
Linker and Loader
Linker and Loader Linker and Loader
Linker and Loader
 
Fundamental software engineering activities
Fundamental software engineering activitiesFundamental software engineering activities
Fundamental software engineering activities
 
Architecture design in software engineering
Architecture design in software engineeringArchitecture design in software engineering
Architecture design in software engineering
 
Object Oriented Modeling and Design with UML
Object Oriented Modeling and Design with UMLObject Oriented Modeling and Design with UML
Object Oriented Modeling and Design with UML
 
Spm ap-network model-
Spm ap-network model-Spm ap-network model-
Spm ap-network model-
 
Selection of an appropriate project approach
Selection of an appropriate project approachSelection of an appropriate project approach
Selection of an appropriate project approach
 
Wimp interface
Wimp interfaceWimp interface
Wimp interface
 
distributed Computing system model
distributed Computing system modeldistributed Computing system model
distributed Computing system model
 
Mobile hci
Mobile hciMobile hci
Mobile hci
 

Destacado

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 Widgets
Ahsanul 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 API
Ahsanul Karim
 
Android before getting started
Android before getting startedAndroid before getting started
Android before getting started
Ahsanul Karim
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)
Ahsanul 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 Development
Ahsanul Karim
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
Ahsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
Ahsanul 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 Overview
Ahsanul 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 Primer
Ahsanul Karim
 

Destacado (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)
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
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
 

Similar a Android MapView and MapActivity

Android chapter25-map views
Android chapter25-map viewsAndroid chapter25-map views
Android chapter25-map views
Tran Le Hoan
 
Maps API on_mobile_dev_festbangkok
Maps API on_mobile_dev_festbangkokMaps API on_mobile_dev_festbangkok
Maps API on_mobile_dev_festbangkok
ss318
 
Android mobile application for gps
Android mobile application for gpsAndroid mobile application for gps
Android mobile application for gps
Sutej Chakka
 
Location based services 10
Location based services   10Location based services   10
Location based services 10
Michael Shrove
 

Similar a 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
 

Más 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 Started
Ahsanul 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 ListViews
Ahsanul 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 ListViews
Ahsanul 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 lifecycle
Ahsanul Karim
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
Ahsanul 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 Activities
Ahsanul 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 overview
Ahsanul Karim
 

Más de Ahsanul Karim (18)

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
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
 
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
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Último (20)

Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

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