Geofencing + Places SDK for Android with Kotlin | Masterclass | Stevdza - San | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Geofencing + Places SDK for Android with Kotlin | Masterclass

teacher avatar Stevdza - San, Android Developer & UX/UI Designer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

67 Lessons (8h 57m)
    • 1. Introduction

      3:29
    • 2. Dependency Overview

      2:18
    • 3. Application Design Preview

      3:27
    • 4. Geofencing API Limitations

      12:24
    • 5. This Project is on Github

      0:30
    • 6. About Places API

      10:07
    • 7. Place IDs

      3:58
    • 8. Place Types & Data Fields

      5:03
    • 9. Session Tokens

      2:10
    • 10. Connect the Project with Google Cloud Platform

      5:29
    • 11. Generate Release API Key

      6:20
    • 12. Autocomplete Widget - Fragment

      13:49
    • 13. Autocomplete Widget - Activity

      7:27
    • 14. Constrain Autocomplete Results

      8:32
    • 15. Get the Current Location

      7:14
    • 16. Get a Place by ID

      8:28
    • 17. Get Place Photos

      6:24
    • 18. Get Introduced with Application Design

      4:30
    • 19. Implement Navigation Component

      8:48
    • 20. Design PermissionFragment Layout

      6:39
    • 21. Create Permissions object

      7:49
    • 22. Create DataStoreRepository

      7:31
    • 23. Create SharedViewModel

      4:34
    • 24. PermissionFragment

      16:50
    • 25. Connect the Project with Google Cloud Platform

      9:21
    • 26. Design Step1Fragment Layout

      10:14
    • 27. Step1Fragment - Part 1

      16:17
    • 28. Step1Fragment - Part 2

      8:51
    • 29. Create Step1Bindings

      14:42
    • 30. Handle the ProgressBar

      6:15
    • 31. Design Step2Fragment Layout

      11:20
    • 32. Step2Fragment - Part 1

      12:50
    • 33. Create PredictionsAdapter

      15:46
    • 34. Step2Fragment - Part 2

      8:35
    • 35. AutocompletePrediction - Click Listener

      14:58
    • 36. Create NetworkListener

      8:24
    • 37. Step2Fragment - Error Handling

      12:08
    • 38. Step2Fragment - RecyclerView Item Animation

      4:23
    • 39. Display Google Attribution

      2:16
    • 40. Design Step3Fragment Layout

      6:57
    • 41. Implement Step3Fragment

      13:45
    • 42. Change Map Style

      3:15
    • 43. Design MapsFragment Layout

      5:45
    • 44. zoomToSelectedLocation - MapsFragment

      8:49
    • 45. Setup ROOM Database

      13:54
    • 46. Inject GeofenceRepository

      2:53
    • 47. Draw a Circle on the Map

      13:55
    • 48. zoomToGeofence - MapsFragment

      9:21
    • 49. Take a Map Snapshot

      4:12
    • 50. Add a Geofence to the Database

      6:11
    • 51. readDatabase - MapsFragment

      7:34
    • 52. Create GeofenceBroadcastReceiver

      11:40
    • 53. Start a Geofence

      14:16
    • 54. Reset Shared Values

      6:08
    • 55. Design GeofencesFragment Layout

      5:07
    • 56. Design geofences_row_layout

      11:18
    • 57. Motion Layout - geofences_row_layout

      4:27
    • 58. Create GeofencesAdapter

      9:06
    • 59. Display Geofences in a RecyclerView

      5:28
    • 60. delete_imageView - Handle Click Event

      6:21
    • 61. removeItem - GeofencesAdapter

      15:51
    • 62. snapshot_imageView - Handle Click Event

      8:11
    • 63. Animate geofence_recyclerView

      2:02
    • 64. Transition Animations - Navigation Component

      13:02
    • 65. Final Word

      1:48
    • 66. Step1Fragment - App Crash Fixed

      2:00
    • 67. jcenter() Migration, Easy Permissions, Dependency Update

      3:14
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

98

Students

--

Projects

About This Class

Hello there and welcome to my course, in this course I'm going to teach you everything you need to know to implement Geofence API in your project. And not just that, as a Bonus I'm going to teach you how to integrate Places SDK for Android as well.

Now this is not the course where you will learn just the theory, this is the course where you will combine theory with practice, and also create one Android application which will use both Geofence API and Places SDK. First I'm going to start this course by introducing you with Places SDK for android. You will learn how to connect your project with the Google Cloud platform, and generate an API key as well. After that you will learn more about Places Autocomplete widget, how we can use it to receive different kind of places as a response. Also how to get more details about the specific place, then how to get places information around your current location, and place photos as well. Plus You will learn more about place ID's, place types, data fields and session tokens.

Now after you get fully introduced with Places SDK for android, we are going to start building our Geofence app. And for those of you who are not familiar, Geofence API combines awareness of the user's current location with awareness of the user's proximity to locations that may be of interest. So basically in our application which we are going to create, we will have a good looking flow to get more information from a user regarding the creation of a Geofence. We will be able to create multiple geofences in our app and get notified whenever we ENTER/EXIT OR STAY within the Geofence for a specified amount of time.

Now I have already prepared design project which we are going to use in this course, so you don't have to worry about that. Also that design project will be available to you for FREE along with the source code of the project on which we are going to work on. The source code will be available on my Github profile.

So, our app will use the most popular Android Architecture components like: ROOM database, Dagger-Hilt dependency Injection library, Navigation Component, View Model, Live Data, Data Store Preference, View Binding, Data Binding, Kotlin Coroutines, Flow and many more...

We are going to follow the principle of a single activity and multiple fragments. Our application will have six different fragments. And we will also use nested navigation graph in our app.

Now, all my courses are well organized, very informative, and they will provide you with all the necessary knowledge you need to work with the latest android API levels. Plus at the end of the course we will have one special section where I'm going to occasionally upload some course updates, like bug fixes and code cleanups. And that way this course will always be up-to-date.

Now what I want here, I want to include you in this project of mine. I want to make you think, like a real developer. After we finish this course and building our app, I expect you to look into the code again and suggest what else could be improved in the app which we are going to create. You can also report some bugs if you find, and even suggest a solution by yourself if you have one.

Anyhow, there is a 9hours of high quality content waiting for you.

So what are you waiting for, let's get started developers!

Meet Your Teacher

Teacher Profile Image

Stevdza - San

Android Developer & UX/UI Designer

Teacher

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction: Hello there and welcome to my course. In this course I'm going to teach you everything you need to know to implement the geofence API in your project and they're not adjust that. As a bonus, I'm going to teach you how to integrate Places SDK for Android as well. Now, this is not a course where you will learn that in just a theory. This is the course where you will combine the theory with the practice and also create one or Android application which will use both the geofence API and the places SDK. First, I'm going to start this course by introducing new with places SDK for Android. You will learn how to connect your project with the Google Cloud Platform and generate an API key as well. After that, you will learn more about the places that auto complete widget and how we can use it to receive a different kind of places as a response. Next, you will learn how to get more details about the specific place, then how to get places information around your current location and place photos as well. Plus, you will learn more about the place IDs, plays types, data fields, and their session tokens. Now, after you get fully introduced with a places SDK for Android, we're going to start building our geofence application. And therefore, those of you who are not familiar. Geofence API combines awareness of the user's current location with awareness of their users proximity to location that may be of interest. So we're basically in our application which we are going to create, we will have our good-looking flow to get more information from a user regarding the creation of a geofence, we will be able to create multiple GeoFences in our application and get notified whenever we enter, exit or stay within the geofence for a specified amount of time. Now, I have already prepared a design project, which we're going to use that in this course. So you don't have to worry about that. Also, that design project that will be available for you to download for free along with the source code of this project on which we are going to work on in the source code that will be available on my GitHub profile. So our application, we'll use the most popular Android architecture components like a Room database, dagger, a hill dependency injection library, navigation component, view model, live data, datastore preference, view binding, data binding causing coroutines flow and many more. We're going to follow the principle of a single activity and the multiple fragments, our application, we will have a six different fragments and we will also use a nested navigation graph in our application. Now, all my courses are a well-organized, a very informative, and that they will provide you with all the necessary knowledge you need to work with the latest Android API levels. Plus, at the end of this course, we will have a one, a special section where I'm going to occasionally upload some course updates like bug fixes and the court clean-ups. And that way these squares will always be up-to-date. Okay, so lastly, I want to include you in this project of mine. I want to make your thing like a real developer. After we finish this course and building our application, I expect you to look into the code again and the suggests that what else could be improved in this application which we are going to create. And you can also report some bugs if you find and even suggests the solution by yourself. If you have one. Anyhow, there is a nine hours of a high-quality content there waiting for you. And what are you waiting for? Let's get started. Developers. 2. Dependency Overview: Hello there and welcome back. So in this video, I'm going to show you all the dependencies and plugins which we are using in our project. So first, on the top of our Gradle build file application module, you can see that we have a plugin select Katlyn kept, then a dagger a hill, then are safe. Args and Kotlin power supplies as well. Then down below, if we scroll, you will see that we have a view binding in that data binding enabled as well. Then finally down below we have our dependencies. So we have some lifecycle dependencies that some coroutine dependencies. We also have added here a coil image loading library. Then down below we have our places as decay of course, then we have it easy permissions and easy permissions is a one amazing library for handling a runtime permissions in your products. Then we have a room library, then we have a day or he'll library. After that, we have a data store n. Finally, we have this map utils library, and there are certain classes which we're going to use from this util library to calculate some things and you'll see, so in the next Gradle build file here we have a class pass for our dagger here Library in for our navigation safe args, and this is our Android manifest file. So here, our application, we will have only two permissions, access final coercion and access and background location. So from API level 29, if you want to access a background location from your application, and then you need to declare in the request the runtime permission for a background location. And of course, if you are using an API levels lower than at 29, then this background location is automatically granted. But for new API devices, you will need to request the runtime permission for our background location as well. Here, as you can see inside our application, we have our broadcast receiver, which we are going to use. Then down below we have declared our Google Maps API key as well. And we're going to have only a single activity and the multiple fragments and our activity will be available only in this portrait mode. And now you saw what the dependencies, which we're going to do is inside our project and what the permissions we are going to need as well. And for this video, and that'll be all. 3. Application Design Preview: Hello there and welcome back. So in this video, I want to show you our application design. And I feel design this application using Adobe XD. So our application I will have a single activity in multiple fragments. And in this design projects, you can see that we're going to have a six different fragments. So, uh, later in this course. So we might add some more views in those are fragments. But for now this is how our designer should look like. So first here we have permission fragment, and this will be a first destination inside our navigation component. So whenever we first time allowing our application, this permission fragment that will be shown, and basically from here, we will be able to grant fine location permission to our application. So we're not going to request both of those are permissions, like a final location and beggar on location permission at the same time, because that's against the new permission rules. So you need to request those permissions sequentially one by one. And here we went to request only one permission, which is a final location permission. And after regret that permission, then we're going to immediately navigate to step one fragment. And that's only when we launched our application for the first time. When we launch our application for the second time after we grant this permission, then we're not going to cities permission fragment. Instead that we're going to immediately switch to our maps foramen here. But if you are running this location for the first time, then you're going to get to Step 1 after permissions fragment. And here you'll have an option to select the name of your a geofence, which you want to add inside your application and inside this fragment also in the background. Now we're going to request location from our user so we can extract the country code from our user. And we're going to use that country code to restrict this auto-complete widget from our places as decay. And you will learn more about this autocomplete widgets later in their scores. Anyway, once you go and click Next here, you will be able to go to this second step. Then from here, you will have the option to select which city or which city you want to add your geofence. And you can just select whatever city you want. And after that, you can just go to this third step where you have an option to select the radius of your geofence. The minimum value will be 500 meters and the maximum value will be ten kilometers. So of course you can change those values if you want. That's on you. And after you click Done, you'll get to this some maps fragment. And from there you will see one, our TextView message, which will say a long press on the map to add the geofence. And then you will have to basically zooming and see whatever you want to add that the geofence. And the first time you long press here on the map to add the geofence, you will be prompted to grant a runtime permission for a background location because otherwise, you will not be able to use this geofence API. And after you successfully add that the geofence, then inside this GeoFences fragment, you will have a list of all the GeoFences which you have added to your map. And of course here you can see some more information about those GeoFences like this snapshot than a geofence name, location, coordinates, and the radius. And of course, we're going to implement here MotionLayout so we can now remove those GeoFences one by one. And basically that's how our application design will look like. And of course, this design project will be available for download. So don't worry in and if you wish to learn how to design your Android applications, then you should check out my other course about the material design for enjoyed and for this video. And that'll be all. 4. Geofencing API Limitations: Hello there and welcome back. So in this video, I'm going to show you how our final application will look like. And the after that, I'm going to talk about some geofence API limitations. So the first thing I'm going to run this application for the first time on my Android emulator. So as you can see, when we run our application for the first time, we're going to see this fragment, which will ask us to grant our replication this permission in here. Basically we are requesting a fine location permission from our user and not both of those permissions like final location in the background location. So we're going to request that those runtime permissions sequentially, like the official Android documentation says in 1st here we're going to request only final location permission. So click Continue button. And then here is can see you will be able to allow this permission or deny. So if you click the NIH, of course, you will not be able to proceed. And basically you will be prompted to open up application settings to enable that permission manually. But in this case I'm going to allow this permission. Okay, so now we have received this toast message that our permission was a successfully granted. And now if I click Continue button, step one fragment that we'll start. And as you can see, this navigation flow from our permission for a man to step one fragment will be only when you are first time installing this application and the next time you run this application, you will not see this permission fragment nor this step 1 instead maps fragment that will be shown. Nevertheless, this is the first time we're running these applications. So here we have an option to name our geofence, okay? And here let's just name this a geofence for example. And we will type the name of my YouTube channel. Now, cane. I'm going to press Next. Then here on our step 2 fragment, we have this auto complete widget from our places as decay. And we have a programmatically design this auto complete widget to fit our needs. Next, let's hear a type. For example, some city I'm going to type or Belgrade, our case or Belgrade. Select that. And now we will be able to go to our step three. So let's click Next. And from here we need to select the radius of our geofence. So for this case, I'm going to select that 500 meters, but of course you can't change that to up to thank you all mutters, solid. Just a switch that to 500 meters and click Done. So after that, as you can see, we have received this text or message which says a long press to add the geofence on the map. And of course, we have successfully zoomed in to our current user's location, which is a Belgrade, of course, here I have said this location to being a valid grade in here also we have one route, and after that, I'm going to start this route to see if we're willing to receive notification whenever we enter, exit or dwell inside our a geofence. So the first thing you can see that we have a two floating action buttons here. And this bigger floating action button will are basically navigate us to our step one fragment to add another geofence. And if we press this smaller floating action button, we're going to open up our GeoFences fragment. We are, we are going to see all our GeoFences. So if I open that up, you're going to see this message that says no geofence found and this message will disappear when we add our first geofence. Now if I try and long press here on the map, I'm going to get prompted to give our application our background location permission. So only if we allow this permission, we will be able to start our geofence. So I'm going to just select these keep while in use access. So I'm not going to grant that in here. We're going to receive a message that says Background location permission is essential to this application. And without it, we will not be able to provide you with our service. And if you click Okay, then you will be basically prompted to go to application settings to enable that permission manually. And I'm going to click Cancel for now. And I'm going to zoom in here OK. To our location, right? So I'm going to start this route with a speed of one x just for a second. Okay? And here, let me just zoom in a little bit more. And I'm going to add this geofence right here. So I have a long press on the map and I need to grant this permission first. So let's click Okay, now let's allow that all the time. And now let's long press here. Are OK. And now you just wait until this geofence starts. And immediately after it starts, we went to receive this notification geofence exit. So that means that currently we have our user's current location outside of this geofence. And now I'm going to increase this playback speed or this speed route to a five x. So we can actually see how our device is getting inside this a geofence. And then after we get inside this geofence, we're going to receive another notification I, which says enter. And after spending five seconds inside this a geofence, we're going to receive another notification, dwell. Okay, so they just wait. Okay, so here it is, enter and after five seconds, dwell. So dwell basically means that we're going to be inside this geofence for a certain amount of time. And we can specify that time. I have specified that time, 25 seconds only. So we can actually see that notification here. And I'm going to start this route again. But this time I'm going to close this application and I'm going to remove this notification or k from here. So now I'm going to basically remove this application and I'm going to start a Google Maps. Okay, so as you can see, our application is currently closed, and here we are inside our Google Maps application and not our application. Our application is closed. And the Nevertheless, in a couple of seconds, you're going to see that we are going to receive a new notification that we have entered our geofence. So let's just wait a little bit. Okay, so here it is, amplification Enter and now after five seconds notification as well. All right, perfect. So now we can wait a few seconds more so we can leave this and geofence and you will see that we are going to receive exit the notification. So let's just wait a few seconds more, our case, so here it is. I'm notification exit. So basically we have exit, our geofence. So I'm going to stop this route now we don't need that at this moment. And you saw that basically we have closed our application and we have opened the only our Google Maps. Okay, So now let me just run this application one more time now. Okay, Let's open now this GeoFences fragment. And here we have our geofence. Okay, so here the name of our geofence here we have a snapshot of our geofence. Then we have a location coordinates in the radius. In of course here we can just Remove this and geofence by clicking this button. Or we can select this GeoFences snapshot and we can zoom into our geofence solid. Just select that. And as you can see, we have a immediately zoom into that. Same a geofence on our eye will go map. So basically this is how our application will work. And now I'm going to talk about some geofence API limitations. So basically, from API level 2019, there are a few changes which were made when we are talking about allocation on our device, specifically a background location. So from now on, we will not be able to use beggar and location are constantly for our application. And basically if we tried to start our route again without having our application opened or any other application like a Google Maps, then we will not be able to receive that the geofence notification. Okay. So we're going to be able to receive our notification from a geofence even if our application is closed or dead. But we need to open up some other application which has Google Maps, okay? And only then we will be able to receive our information from the bare ground from our geofence API and show a notification end if we close all of those applications and we will not be able to receive those geofence notifications. You might be wondering about how can you use our geofence API properly? Well, there is one way. And for that, let me just open this web browser and you can access this page on the specific link. So in order to use their background location fourth time, now without needing to open some other Google Map publication like just we did, then you need to request a special background location permission. In here it says that you can submit your application for feedback on occasionally in the background x is by completing this location permission declaration form in a play console. So basically you need to upload your application to a place console. And from there you just need to feel this forum. And after that, they will basically send you a message to approve your application. But there are a few more requirements which you need to complete. So here it says that, uh, your application there should not request access to a location in the background unless it's required. And if your application requests access to location in the background, but it's not critical to your application's core functionality, then you must remove it from your app and or implement location accessing the foreground, such as when your applications activity is visible to users. So here if you open this timeline down below, you're going to see that from January 18th, 2021 or new applications first published the after April 16th, 2020, submitted to a Google played that access location in the background, we will need to be approved before they can go live in from the sun March 2009, all existing applications that access location in the background we will need to be approved or app updates may be blocked and your application may be removed from Google Play. So basically, in order to use the geofence API full time without any restrictions, you're going to need to fill out that form from a Google Play Console. And from there you need to describe your application in a few more information. Down below, you also have some guidelines. So for example, before you start, you should review best practices for accessing location. Then also you can consider alternatives to accessing location in the background and make access to a location in the background clear to your zone. So basically, our application is a well-designed and its core functionality requires a beggar on location permission because we are using a geo fencing API and without a background location permission, we will not be able to provide that functionality to our users. So there is a good hypermobility that your application and will be approved if you'll follow all those guidelines. And down below you can see that you also need to provide a video demonstration of your application. You can just record your application how it works, and just describe what information and you're going to receive or get from users, how you're going to request those runtime permissions and basically some other information which you can find here as well. So be sure to check out this link and you can read more about it. So this application which we're going to create will work perfectly fine, except when we're not using any application which has a Google Maps in a foreground, even though we are using a background location permission, our functionality is kinda restricted and we will need basically to fill up and send this form to our place console so they can now review and approve our application. After that, we will be able to use our geofence API in our applications with all its functionalities. So there is one more thing are important for a geofencing API, which you should know, and that is the number of GeoFences which you can create in your applications per user, and that number is 100. But nevertheless, if you are going to use more than 100 GeoFences, then you should create a different logic for your application. Anyway, geofence API is great API and you can create them many different useful applications. You can also create a semi parent-child application where you can where you can send a notification to apparent whenever child leaves or enter a summer geofence and in your score so you will get all the necessary logic tool, create, and handle. Geofence isn't in your application, but of course, so don't be scared. If you need to request this special permission as you just need to create an account on a play console, upload your application there, fill out this permission declaration form and just wait until they approve it. So for more information, feel free to visit the selling and therefore this video that will be all. 5. This Project is on Github: Hello there and welcome back. So this is going to be a really quick video because I just wanted to share with you this geofence application, which is uploaded on my GitHub profile. So you can see you can access this repository on this link. So on my GitHub profile slash geofence application. And here you can just download this project. You can look into this source code, compare it to your own, and basically do whatever you want. So that'll be all for this video. 6. About Places API: Hello there and welcome back. In this video, I'm going to give you more details about a place as SDK for Android. And I will introduce you with that API in general in their show you what functionalities this same API has to offer. So here inside my web browser, I have opened the page for official documentation for our places, SDK for Android. And they're here, we're going to read this documentation together to see some more information about that. So for those of you who are still getting to know these places as decay, it's basically a library that allows you to build a location aware applications that the respond contextually to the local businesses and the other places near the user's device. So we're basically a Places API is a one and a huge database which consists of a large number of places like businesses and the other points of interests. And they're basically using these places as decay. We are basically querying data, huge database to search for something specific locations which are available around us. So this SDK provides us two main interfaces, places and the auto-complete. So places provides programmatic access to Google database or for local place in their business information, as well as the device's current place. And using these places interface, we can basically get a lot of information about those places around us. And you will see about that in the future videos of this course. And also we have this auto-complete, which is basically a pre-made widget that returns the place predictions in response to user search queries in, I'm going to talk about this auto-complete details in some of the next videos. But for now, what you should know is that this autocomplete offers you a way to query that huge Places API, database and the receive some location predictions so while you type. Okay, So we're down below here we can see this APR overview. So as I already mentioned that we can use this AutoComplete functionality. Then we have this occur in place, which basically returns a list of places where the user's device is a less known to be located along with an indication of the relative likelihood for each place. Then we have a place details which returns play more detailed information about the place. Then we have a place, photos which returns are high-quality images of a place. And finally, we kept our place IVs, which is basically our unique ID for one or more places for retrieval of place information on demand. So basically, each and every place or a location or a business or some other point of interest have a unique place ID. And I'm going to talk about place ideas in some of the next videos. So for you to use this. Places SDK for a Android, you will need to create a project inside the Google Cloud Platform. So as you can see, this is a Google Cloud Platform and hearing to create the project and the enable our billing account. So I'm going to talk about creating the project on their Google Cloud Platform is on the next videos. And also I'm going to show you how you can automatically create that account from your Android Studio by just generating one link. And you will see about that later when we start experimenting with some of those functionalities of Places API. So one important thing for places SDK for Android is that you will need to enable billing account to your Google Cloud Platform. So places SDK for Android is a paid service, and that's why you will need to create a billing account in Google Cloud, the platform as well. And don't worry, I'm going to show you how to do that as well. So even though this is a paid service, there is a catch. So here it says that for each billing account for a qualifying Google Maps or platform SKUs to a 100 dollar Google Maps platform credit is available each month and the automatically applied to their qualifying SKUs. So what that means that each and every month you are going to get a free $200 credit for your Google Cloud Platform account. And while I was working with places SDK for Android, I spent over a month testing geofence application using these places as decay, and I didn't spend even a $100. So that means that the $200 are free credits, which you're going to get every month. And that's more than enough credits for you to experiment whatever you want with your project. And of course, if you are planning to publish your application on Play Store and have a thousands of user, then you would probably need to pay more for these service. But for some basic usage, those $200 credits are enough. And here it says that usage in billing works under the pay as you go model. So that means that you will pay only the things you will span there. You will not pay anything if you don't spend, those are $200 of credits. So only if you spend all of those to a 100 dollar credits, then you're going to get to build and butter, don't worry. You're not going to spend those that are a $100 credits that easily. And down below in this documentation, we can also check some pricing. So here you can see how many requests you will need to spend to get billed. For example, $3. So for example, here we have contact data. So for using the only contact data, you will get billed only $3 per 100 thousand requests. And the down below we can check some other data like atmosphere, data like autocomplete and so on. So for example, here we're going to get billed to $0.83 per, per 1000 requests. And if you have more than 100 thousand requests, then you're going to get built a little bit less, for example, to 0.27 per 100 requests and so on. So you can check those details. Furthermore, I'm not going to stick with that any longer. But the main thing here is that those 203 credits are more than enough for you to work on any project you want. And of course, on Google Cloud Platform, you can just Check how much have you spent. So here inside my Google Cloud Platform, I can show you my your billing in basically, in the previous month, I hear a spend and $92.61 for the whole month. And as I already mentioned, we have a $210 credits free every month. And I have spent almost 50 percent and I have used this API so much for over a month. So that means that you don't have to worry about spending those $200 credits because it's a lot. And of course on your Google Cloud Platform, you can check in real time how much credit so you are spending, so you don't have to worry about that. And also there is a way for setting a limit on how many or how much money can you spend that daily. Also, there is a way to manage your cost or through Google Maps platform APIs. And you can set a daily quota limits on all requests to any billable API. So here when I open this sewing so Cloud Platform console, then you need to select your project. And I'm going to select this geofence demo which I have been working on. Then on the left side here I can select quarters, and here I need to select which API I wanted to check. So for example, I want to limit this Places API I'm in here. I need to open this so requests table. And here I can see how many requests him I used per day. So for example, here you can see that the most requests I sent on February 22, and it was almost one hundred, ten hundred and two hundred requests. And down below, if I scroll, we can see that here we have some elements. So here we have our requests per minute, and those requests are limited to 6 thousand, but we can also limit the requests per day. So we can limit, for example, one hundred and five hundred requests per day. In here, I can just enter the number which I want. So just uncheck this option in here. I can write, for example, one hundred and five hundred requests and just check these confirmation option and click Save. So that way you can control how many requests you are using per day. And that that way you will not be able to send more than one hundred and five hundred requests per day for these Places API. But of course, I'm going to set that to our emitted because I will not be able to spend more than that. But I just wanted to show you a way for you to basically limit your API so you don't get billed at the end of the month. But of course, as I already mentioned, that you're going to have a $200 so for free credits every month for your project. And that's a lot. So that'll be all for this introduction videos. So we're now you have learned what these Places API actually is, how it's working, what functionality does it have? Also, I have shown you how to limit your API, your search. Also, you have learned that for this Places API, you're going to need to have a billing account. And I'm going to show you how to create that billing account once we create a new Google Cloud project here, and we connect that to our Android Studio. And for this video that for you all. 7. Place IDs: Hello there and welcome back. So why in this video we're going to read the documentation for our place ideas together. So basically before we actually start experimenting with places SDK for a android inside our Android Studio. I want to read this documentation together so we can see and learn some more things about these places as decay in general. So Place IDs, so Place IDs uniquely identify a place in the rural places database and on Google Maps. So each and every place on a Google map is associated with some a unique place ID. And basically you can type here and that unique ID and you can search for a specific location. Down below you can see some examples of how this place ID should look like in the length of this identifier may vary. So for example, you can have a shorter or a longer place IV depends on the actual location. So we'll place IDs are available for most locations, including their businesses, landmarks, arcs, and the intersections. And also it is possible for the same place or location to have a multiple different place IDs in place ideas may change over time as well. You can also use the same place ID across the Places API in number of Google Maps platform APIs like Places API, Maps, JavaScript API, Maps, geocoding, Maps, embedded, and the Roads API. There is also one important thing which you should note. So a place IDs are exempt from other caching restrictions started in this 3.2.3 B section, or for Google Maps or platform Terms of Service. So let me just open this section so we can read that together and also place IDs are exempt from other caching restrictions. Starting this 3.2.38, this time of Google Maps platform Terms of Service. So now let's read those paragraphs. So let me just find that 3.2 or 0.3 or k. So restrictions against nice choosing the service. So a and B here it says no scrapping. And here it says that a customer will not export, extract, or otherwise scraped by Google Maps or content for you is the outside of the service. So for example, our customer will not prefetch, index, store, reshare, or rehost their Google Maps or content outside the services or bulk download Google Maps, tiles or Street View images, geocodes, directions and distance matrix results are roads information and places information, elevation of values that time zone details, copy and save our business names, addresses, or a user reviews or use Google Maps or content with a text-to-speech or services. And section B here it says and no caching, so a customer will not care. So Google Maps or content, except as expressly permitted under the maps or services specific terms. So what it means that you as a customer will not be able to scrap those are information. So you will not be able to store those information which you get from these Places API. But as you can see, these place ID is exempt from that. So you can store this place ID locally. For example, in the, you can use this same place idea later. Search for that same location. So that's kind of a workaround for this legal issue. So those were some of the important information about the place ID that you should remember. And now you have learned about this place ID 1, that is, and how to use it in your application. And of course, later in this course. So we're going to use a place IDs to basically fetch the data from a Places API. So well, that'll be all for this video. 8. Place Types & Data Fields: Hello there and welcome back. So in this video we're going to read the documentation for a place types and their place data fields. So it is important to know what kind of place types in that place data fields. This places the SDK has to offer. And here as you can see, it says that there are three tables for a place types. In the first table lists the types that are supported for a place searches and can be returned with a place details results and as a part of auto-complete place predictions. Then we have a table to which lists additional types that can be returned with a place details the results, and there is a part of auto-complete place predictions. And the table three lists types that you can use in a place autocomplete requests only. So if we scroll down below, you will see that this first table is used in the following ways. So as a part of a place details response, then as a part of auto-complete place prediction and in the type parameter of a place searches, for example, to restrict the results to all places matching the specified type. And that there is a lot of types here which you can see. So for example, accounting, airport lawyer or library, bank, bar, cafe, museum, park, parking, casino polys, sparse stadium storage and so on. So you can check this documentation NC, the whole list. Then down below we have additional types returned by the places Service, which is a table tool and it's used in the following ways. So as the part of the result of a Place Details request or anywhere a place result is returned then as a part of auto-complete place prediction and to denote address components. And down below you can see this second table is a little bit smaller. So we have, for example, continent, premise room, route floor, food shelter, geocode, landmark, neighborhood, and so on. And finally we have a table 3. So here we can see a types that are supported in a place, autocomplete requests. Here it is said that you may restrict the results from a place that autocomplete to request to be of a certain type of bypassing a type spirometer. So our later in this course, when I show you how to use place autocomplete, then you will see that you can restrict the actual types or details which you want to retrieve for these places as the key. And the down below, as you can see, the supported types for this table 3 is a geocode address then establishment, which instructs the place autocomplete service to return only business results, for example, then we have our regions, and finally we have our cities, Sowell. You can see here that there are so many supported types for our places SDK. And that's why I said in the first video of this course that these places as decay is one huge database which consists of basically all places around the world. Next, we're going to read this documentation for a place data fields. So a place data fields and define the types of plays data to return when a requesting a place details. And down below we can see some are basic data. So here we can find the fields which may differ from API to API. So for example, here we have places library Maps, JavaScript API. Then we have places SDK for Android and iOS, but we're going to focus on Android for now. And as you can see inside this table for basic data, we can find some fields like address components, then our business status than address, then a view port, then a lat long than a name, photo metadata's IDs plus code types and the UTC offset and the one we start working with our auto complete widget. Then you will see that we can restrict what fields we want to use from our places. There's decay, for example, we can only set to search different addresses and nothing else or just the lat long information. Then down below we can see some eye contact data fields. And here we have our phone number, opening hours, and the website URI. Then down below we have an atmosphere data fields. And here we can find a price level rating in the user ratings total, and that this data is used for some business occasions. And the down below, as you can see, this fine current place function does not support the following fields like address components, opening hours, phone number, and website URI and the UTC offset. And this final current place functioning is a part of places client class, which we're going to cover in some of the next videos, of course. So for this video, that will be all. And now you saw what plays types and the data fields we have with our places as decay. 9. Session Tokens: Hello there and welcome back. So we're in this video. I want to introduce you with session tokens. And session tokens are important when we are talking about place autocomplete because it uses a session tokens to group the query and the selection phases of our user autocomplete search into a discrete session for billing purposes. So the session begins when the user starts typing a query and the concludes when they select a place in call to place details is made. So each session you can have a multiple autocomplete queries followed by one place selection and API keys used for each request within a session must belong to the same Google Cloud Console project. And once a session, Here's a concluded that token is no longer valid and your Application Master generate a refresh token for each session. And down below we can see some are guidelines for our session tokens. So I use a session tokens for all autocomplete sessions, generate a refresh token for each session. Ensure that the API key is used for all auto-complete in place details that requests within a session belongs to the same Google Cloud console project and be sure to pass a unique session token for each new session. And down below we can see some example. So as the user types a query in autocomplete to request these called the every few keystrokes and not per character, and a list of possible results is returned. And there when the user makes a selection from the result list, then the selection accounts as a request and all the requests made during the surge are bundled and counted as a single request. And down below, as you can see, if you want to create a session token, then you need to call this autocomplete session token and it's a method name their new instance. And don't worry if this concept of session tokens is a confusing at the moment because I, once we start working with our place autocomplete, then everything will make more sense. And for now, I just wanted to read this documentation together with you so you can get introduced with this concept of a session tokens. And that'll be all for this video. 10. Connect the Project with Google Cloud Platform: Hello there and welcome back. So in this video, I'm going to show you how to connect your Android Studio project with Google Cloud Platform. So in order to use Maps, SDK, and Places API, you're going to need to connect your Android Studio project with Google Cloud Platform. Also, you're going to need to generate some API keys and of course, that create a billing account. So the creation of a billing account will be covered in some of the next videos. And for now we're going to focus on connecting our Android Studio project with Google Cloud Platform and generating, debug your API key. Well, there are two ways of connecting your Android Studio project with the Google Cloud Platform. So the first way is the manual way and you can just navigate to Google Cloud Platform website. And from there you can just manually create one simple project. In the other way is an easier way. So basically, we can create Google Cloud Platform project using our Endrew in Studio. And then now I'm going to open up Android Studio. So here I have just created a simple project with one activity. And then now I'm going to create one more fragment inside our project. And that fragment that will hold the Google Map. So let's go to a foramen here and from templates, and we're going to select Google Map fragment. So Google Maps or fragments or select this template. And the reason why we are going to select this template because there are certain files which will be generated automatically for us. And now let's create that maps fragment. I'm going to leave that as it is and click Finish. Okay, So now as you can see, some files were automatically generated for us. So we have our maps fragment and also we have received a new file name, the Google Maps API XML. And inside this file, as you can see, there is one more string which needs to be filled with our API key from a Google Cloud Platform. And also this Google map template for our fragment has generated the one important link for us, which we're going to use to basically create our project in connected with Google Cloud Platform very easily. So here we just need to copy this selling. Let me just copy this link or, kay? And now I'm going to paste that link on my web browser and just press enter. So this link will redirect us to our Google Cloud Platform, our website. So just the weight a little bit. And from here you can select all your projects. So if you have a manually created some project, then you can select that right here. But I'm not going to select hear anything. I'm going to just click continue because we want to start from the beginning of course. And the now we need to click this button which says create an API key. And the API key will be a debugger API key. So there are two types of API keys, debug API key and the release API key. So the main difference between those two API keys is that and debug your API key cannot be used in a production. So it can be used only while our testing your application. And if you want to publish your application and use it on a real devices, then you're going to need to generate a release API key as well. And I'm going to cover generating a release API key in the next video. For now, we have just created a simple project on our Google Cloud platform, and we have successfully connected that project with our Android Studio. And of course, this API key was automatically generated for us. And these API key is a debug API key. So this is the actual key and we can just copy that. And now we need to get back to Android Studio here, where it says your key here, we need to replace that text with our actual API key. So now we have basically added that API key and we can freely use Google Maps on our application. So if you don't add this API key, then you will not be able to use Google Maps on your application. And now let me just switch this to a project views so I can show you or something. So here as you can see inside our source directory, we have two directories. We have a debug and release. So both of those folders have this file. So as you can see, they are basically named the same. But if we open up this release aversion, you all see that basically another, a different file and we have basically created this API key for our IV bag. And in the next video I'm going to show you how to generate the release API key as well, so you can use this application into production. But of course I'm going to close that now. I just wanted to show you that there are two separate files which needs to be populated with those API keys. And now we have basically connected our project with the Google Cloud Platform and we hear a generated those data debug API key. And we have in whichever base that, that API key right here, which is fine. And now we can use our Google Maps. We know any issue and this is our maps fragment. We're going to modify this maps fragment in some of the next videos. For now, I just wanted to show you how to basically connect this project with Google Cloud Platform in how to generate a debug API key. So in the next video, we're going to generate a release API key as well. And the after that, we're going to continue exploring some places API functionalities so you can get introduced. So that'll be all for this video. 11. Generate Release API Key: Hello there and welcome back. So why in the previous video, we have connected our Android Studio project with Google Cloud Platform. And we have also generated this debugger API key for using a Google map, of course. And in this video I'm going to show you how to generate release API key. So a debug API key is only used for Android emulator and for testing these application. But if you want to use this application in production in, on a real devices, then you would need to generate release API key as well. So the first step in generating release API key, we need to build our release aversion. So here inside our Android Studio project, we need to go to Build menu, then generate, sign there bundle or APK. In here we can select the Android app bundle or APK. I'm going to select the APK for now, but you can choose anything you want. And here we need to select the path where we want to store our key. So since we don't have our key yet, we need to create a new one. So click Create New. And here first we need to select the KeyStore path. So I'm going to select my documents directory from here. Okay? In the name of this file will be, for example, it's a places demo, Okay, click Okay. So for the password, I'm going to select one. I'm going to repeat the password here for a key alias, I'm going to select, for example, key 001 and this password there should not be the same as the first one. Okay, here we can type for example, our name and any other information. So I'm going to just leave that as it is for now and click Okay, in here, I can just remember the password and click Next. Then here I'm going to select the release version. And from here I can select both of those signature versions. And now click Finish. So now our weight a little bit, and this release APK file will be generated for you. Okay, so now that our APK was successfully generated, we can proceed to next step. And now I'm going to open up a web browser, and I'm going to open up this URL. So what developers dot google.com slash, maps slash and documentation slash enjoyed forward slash sdk slash. I get four slash API for our slash key. Okay, so this is the actual documentation where we can see how we can generate a release a certificate. And now that we have generated our APK file, we can proceed next and we need to create or generate sha-1 fingerprint. So to regenerate that, we're going to need to basically copy this command. And now I'm going to just copy that. So let me just click this button and it will open up our Android Studio. So now let's open the terminal down below, and I'm going to hit Control V to paste this line of code and they're willing to replace those two values. So the first value is this one which says you're a KeyStore name. So here we need to copy and paste the full path where we have generated our key store. And then now I'm going to open up File Explorer and I'm going to locate my documents directory. Okay, So here it is. And I need to copy this full path. Now came in here, I need to paste that. And also I need to write the actual name of our KeyStore file. So places demo dot j, k, s. That's the name of my file in here where it says alias. I need to type a key Z11 because that's the actual alias which I have chose. So ky 0, 1. So this is the actual command is so key to all space forward slash at least space, forest slash v space for a slash key store space than the actual path that where we have saved our key store In the name of our key store with its extension JK AS then a space for a slash alias, space key 01, because that's my alias. And now press Enter, and it will prompt you to enter the actual password for your key store and just enter that password which you have already chose and press Enter. And now sha-1 fingerprint will be generated with other ones, but we need to copy this one. So sha-1 with me just copy that. Ok, click Copy. And now we open up our Google Cloud Platform and we need to create a new API key, which will represent release API key. So just click here or this plus button. So create credentials, choose an API key and the weight moment here you will see a message that says API key created. So I'll just click this restrict key button and it will open up this second API key. And from here we need to restrict our application to Android applications. And the down below where it says restrict users to your Android apps. We need to select this button which says add an item. And here we need to add to information. So the first one is the actual package of our project. In the second one is a sha-1 or fingerprint. So just paste that fingerprint which we have just generated with our KeyStore and the actual package name. So I can just check out my package name. Okay, So my package name is that com dot example dot the places demo. So com dot example dot places a demo and click Done. Okay, perfect. And the after that you just need to click this Save button and of course copy this release API key are okay, click save, and there we go. So now you have successfully created, generated your release API key as well. And now we can open up our Android Studio project. And we can open up this release a version of our Google Maps API file. And here we can paste our new API key K, and there you go. So now we have successfully generated both of those API keys. And in the next video before we actually continue experimenting some places API functionalities, we're going to create a billing account or on our Google Cloud platform as well. So that'll be all for this video. 12. Autocomplete Widget - Fragment: Hello there and welcome back. So in the previous videos, we have connected our Android Studio project with Google Cloud Platform, and we have also generated the debug in their release, their API keys. And in this video I want to show you how to implement autocomplete widget inside your application. So first, let me just close all of that. And first I'm going to create here a new fragment, which will represent the full fragment inside our navigation host. So for that, I'm going to open up this and irrigation and I'm going to create a new navigation resource file named our nav graph for example, because this file will represent the navigation graph for our navigation component. So press Okay, click Okay to add those dependencies for navigation component. And now just wait a little bit and we're going to create a new fragment now. Okay, perfect. So now let's create a new destination here and there we're going to select the Fragment Blank. I'm going to name this fragment, for example, our first frame and click finish our case. So this fragment will be a default destination inside our navigation graph. And now let me just open this first frame it and I'm going to remove this unnecessary code from here. We're going to leave it just this onCreate view function. Well, we already have this fragment maps which we have created with this default Maps template. And we needed that maps a template in order to generate those debugging the release XML files. So for now I'm going to close that and we're going to focus on our first fragment. So now inside our main activity, I'm going to add here a nav Host Fragment so we can host our destinations from our navigation graph. So just drag and drop that right here and select this navigation graph file. And let's just constrain this nav Host Fragment and with apparent horizontally and vertically our k here we can change this ID to say for example, nav, Host Fragment are okay, perfect. And now default the destination inside our activity will be our first fragment. So let's open up our first fragment to layout our case. So here it is. I'm going to change here our author element will be a constraint layout, and I'm going to remove this default TextView. And here inside our first fragment that we're going to add our auto complete widget. So before we do that, I want to open the official documentation for our autocomplete. In here it says that this autocomplete service in the places or SDK for Android returns place predictions in response to user search queries. So as the user types, the autocomplete service returns suggestions for places such as businesses, addresses, plus codes, and the points of interests. So well, we can use this auto-complete in multiple ways. The first way is the easiest one, and basically it represents already made the auto complete widget, which will save our development time and ensure a consistent user experience. And the second way represents a manual way where we can customize this autocomplete by our cells. And I'm going to focus on this first one and we're going to customize this auto-complete. Widget when we actually start working on our geo fencing application. So down below, when we scroll, you all see this example of how this auto complete widget that looks like. So it's basically a search dialog with a built-in autocomplete functionality. And when a user searches are some terms, then the widget presents a list of predicted places to choose from. And when the user makes us selection on one of those places, then a place instance is returned, which are your application can then use to get into the details about the selected place. So why there are two ways of adding these auto-complete to widget by using this autocomplete support fragment or by using this intent to launch the autocomplete activity. And now we're going to focus on this first way by using this autocomplete support fragment and that we use that we need to just add this XML element fragment with the name of a com dot google.png. Lot libraries, not places, not widget, daughter, autocomplete support fragment. So we can just copy that now and let's add it to our first fragment here. Okay, perfect. And now you will see that here we have an error and that's because we haven't added the dependency for our places SDK for Android. So let's open up our Gradle build file here. Let's scroll down below. And the now instead is documentation and we're going to choose this get started page in from here. We're going to scroll down below and we need to copy this dependency. So let's copy this one, and let's add our places SDK dependency. So let's sing the project now. Okay, perfect. So let's close that now. And as you can see, this error now disappeared. So now let's constraint our auto complete widget on the left, right, and the thought came. And now let me just run the app so we can see if we're going to see our auto complete widget at all, our case. So here as you can see, we have our autocomplete search widget, but if we click on debt, our application will crash. And that's because we haven't implemented any code yet. So let's open up that documentation from earlier. And now as you can see by default, so these auto-complete there we did. He has no border or background. So if you want to add their background, you will have to place this auto complete widget inside that card view, for example. And then on their current view you can modify those properties like background color or stroke, radius and so on. So the next thing that we need to add the place selection, a listener to our fragment. So I'm going to just copy this whole code and add that inside our first fragment. But before we do that, I want to enable our view binding inside my project. So here let's add the view binding to true. And let's sing the project are okay, perfect. And now from our first fragment that we're going to use our view binding. So here we're going to create the two variables. The first one will be a var, so we can actually modify its value. And here I'm going to add underscore binding. And the type here should be a fragment. First the binding in its initial value will be null. Then we're going to create a read-only variable, binding end. We're going to use a getter to get the value of our underscore binding. And of course I'm going to add a double bang operator in here. I just want to call underscore binding in. Then I'm going to call a fragment first binding. And we're going to inflate our layout end. Instead of this hard-coded layout, I'm going to just pass the actual LayoutInflater here. We also need to return binding daughter Ruth, and we need to override here on this Troy view so we can avoid them memory leaks and set underscore binding to now after our fragment is destroyed, of course, we can also remove this question mark. We don't need that. And now let's paste that code. We're tree here we just copied. Okay, so here I'm going to just import this log, then this place selection listener than a place autocomplete support fragment, we can replace this tag with just the tag, and we're going to import this condo, the rule dot enjoy the GMS common API. Okay, So now here, as you can see, we have a warning and instead of this support fragment manager, we need to call child FragmentManager in here. I'm going to remove this line of code and here as well. And now let's run our application and see what will happen. Okay, so let's click on this, autocomplete the widget. And now as you can see, this fragment have appeared in here. We have this powered by Google text in here. We have our search widget in from here, of course, so we can type anything we want and search for us someplace. So let's try and type here something. And as you can see, as soon as I type, one character data fragment disappeared and there, why is that? So let's first check our logcat in here. As you can see, if we type tag, then we're going to see an arrow that says status, status code. This API project is not authorized to use this API and it's because we still haven't enabled our places as the K or now our Google Cloud Platform. So let's open up a web browser and you need to log into your Google Cloud Platform console. Then you need to select your project. And from here, you need to go to APIs and services than the library. And then from here, we need to find that Places API. So let's open that up. And as you can see, these maps SDK for Android was that automatically enabled for us when we actually created this project with data link, which was provided inside our Android Studio. And now we need to enable our Places API. So let's click this button, enable our case. So let's just wait a moment and our Places API is now enabled for our project. So now we can run this application again and see if everything's going to work fine. So let's open this log kit. Let's click on our auto complete widget. Then this widget will appear or this fragment in from here, for example, we can search or some place I'm going to type here, for example, Belgrade. Now as you can see, we have another error. So now we have a status code that says you must enable a building, or now we're Cloud platform, and then now it is time for us to create a billing account. So let's open up our Google Cloud Platform. From here I'm going to select the billing. And it says that this project has no billing account and we can link our billing accounts. So click here, and I have already made my billing account here, so I'm going to slay that account. But for you, you would need to set up this account and you're going to see this option to create a new billing account. From there, you just need to basically add your credit card information in case you exceed that $200 free credits for a month, then you're going to get billed on your credit card. But of course, I already talked about how you can limit your API to not go over a certain amount of requests and so on. So you can just create here a new billing account and link dead. So I'm going to select this account which I have already made and I'm going to click Set Account. And now our billing account is linked to our project now. Okay, and now let's open up our Android Studio project and let's run our app to see if everything's going to work fine. So here let's just type, for example, Berlin. So as you can see, even if I type the two character, I saw this Berlin in the first item of this list. And as you can see, it works perfectly fine. So now let's see what will happen if we just select that one of those items. So let's click for example here. And now let's open up our logcat in here. As you can see, we can see the name of this place, which is the Berlin. In here we can see the actual place IV. And of course we have already talked about place ideas. And you already know that each place ID is the unique identifier for each location on Google Map and inside our own place selected function here, in this place selected listener. And we have implemented this one simple line of code where we have logged the name of our place in the actual ID. And that's basically how you can enable this auto complete widget inside your application using this autocomplete support fragment. And as you can see, it is very easy to set up this auto complete widget. You just basically need to add this one XML element, autocomplete support fragment. And then you just need to initialize these places as the k. And then after that, you need to, I get the reference of autocomplete fragment and then you just need to add on Place, select the listener to listen. When you select one of those places from the list in here, of course, as you can see, we have used this function set place fields to actually set the fields which we want to see inside this auto complete widget list. And as you can see here, we have called this set place fields that function. So we can actually limit the fields which we want to receive from our Places API. And we have basically listed the only two fields, ID, name. And that's the actual information which we have received from our log. But of course, if you want to add some different fields, you can just add, for example, and dress wet longer Business Status, opening hours and so on. So as you can see, you have many of those and we have already seen in those fields on our official enjoy the documentation for that. So that'll be all for this video. So now basically we have a successfully implemented our auto complete widget inside our fragment, I have also shown you how to enable our Places API from Google Cloud Platform in how to add the billing account. So of course, these places, SDK for Android is a paid service, and that's why you need to add billing account. But as I already mentioned in some of the previous videos, every month you're going to get that to a $100 of free credits. That that's more than enough for you to basically work on any project you want. And of course, if you want to publish your application so that thousands of users cannot access your replication and use that service, then you will have to pay for that. But for some are simpler projects, you'll have more than enough credits to work on, and that'll be all for this video. 13. Autocomplete Widget - Activity: Hello there and welcome back. So willing to previous video, we have implemented our autocomplete support fragment. And as you can see, this is how our application that looks like so far. So here we have this auto complete widget. And then whenever I press on this autocomplete that widget, then a new fragment here will appear. From here, we can just type any place we want to search. So for example, I can type here Belgrade, and then I can just select the one of those places or predictions from this auto-complete list. And inside our first fragment that we have defined there, which fields do we want to retrieve from our autocomplete? And here we have defined it. We need to get the ID and the name and the In this video, I'm going to show you another way of implementing this AutoComplete functionality. And this time I'm going to do that with activity. So why there will be a timer when you don't want to use this autocomplete support fragment. And for example, you want to trigger that the autocomplete functionality from some button or icon. And in that case, we need to implement autocomplete the activity. So let's just open this, the official documentation so we can take that out. And here as you can see, this is an actual option number two. So this option number 2 suggests that you should use the intent to launch this. So autocomplete activity. So if you want your app to use a different navigation flow, for example, to trigger autocomplete experience from an icon rather than a search field, then your app, I can launch a autocomplete the biasing in intent. So these are steps that are needed if you're embedding a fragment like we did in the previous video. But now we just want to remove this embedded fragment or we can just forget about that at this moment. So here it says that you shouldn't Cloud Launcher autocomplete activity directly. Instead you should use the intent launch these auto-complete. And down below we can see one example code which we're going to copy in order to show you how this can be achieved. So before we actually start to implementing these code that I just want to create one menu and that menu will be used there from our main activity. So let's first here, create a new menu resource file. So right here, and I'm going to name this file our main menu. So click Okay, and here we're going to only add one simple item. So the actual icon will be a search icon. The actual ID can be Menu. Search, show as action can be if a room, so it will be visible and the title can be a search and color of this icon can be white, now k. So here I'm going to add this target API attributes so we can avoid this, a warning. Okay, perfect. And this is how our menu icon should look like and it will be attached to our action bar on our activity. So let's open up our main activity. And here first, I want to initialize this menu. So I'm going to override on Create. Options manual. And here I want to use a menu inflater to inflate our menu which we just created and hearing to pass our resource. So our menu.html main menu in here, we need to pass a menu as a second parameter. So now let's run our app to see if this search icon will show on our action bar. Okay, so now we can see this search icon. And the next thing Let's go to this documentation again and I'm going to copy this part of the code, and I'm going to paste that code for now right here in say, the onCreate method. And now let's suggest import all of those classes. So all plus enter our k. Perfect, Let's get back to a web browser. So when using an intent to launch this autocomplete the widget, you can choose from overlay or a full screen display modes. And as you can see, those are the screenshots in this first one represents the overlay mode, in the second one represents our full-screen mode. And of course at that code which we have, which we have a copied earlier, is using this for screen mode, which is this second screenshot. But later we can change that to this overlay mode as well if we want our case, let's go down below and also we need to override their onActivityResult function. So I'm going to copy this part of the code as well. And I'm going to open up by Android Studio and also override this function. So on activity result, now let me just put this autocomplete to request code on the top of our activity. For example, right here are k here. Let's just import this intent, then activity, then we can also this log then autocomplete activity. So all placenta or K here I can type, for example, main activity. I can do that here as well. Perfect. In here, I can just convert that to a string. And basically our activity result when we select one of those items from the list or from our autocomplete to Egypt, then this function will be triggered. In here we're going to check if the result is okay. And if it is, then we're going to log this place ID in place name from our auto complete widget as we did in the previous video, like you already saw. And there is only one more thing which I want to do here. So I want to override on options, items selected, and here I want to type when item dot item ID is, for example, let's say our dot id.me search. So when we select our search menu from our ActionBar, then I want to start this intend. So let's just paste this code right here, and also those fields. Okay, perfect. And now let's run our application to see how this autocomplete activity we'll now work. So now as you can see when I press this search icon, then this on options items selected function will be called. And we're going to start our activity for result. And there we go. So this is our autocomplete activity widget, which represents full screen mode. And here we can just type anything we want. And we can select one of those places. And when we select that, we're going to open up our logcat. And here if I type main activity, then we're going to see that we have a logged this place and that place ID. So it is working perfectly fine. And let me just show you that we can also use another mode, which is an overlay mode. So let's start our application again so we can see how well that they look like now. And now when I press this search icon, we're going to see our overlay mode. So this overlay mode is almost the same as our first autocomplete support fragment like this one. So as you can see, they, so they are the same. And now you have learned how to use this auto-complete as an activity and also as autocomplete support fragment as well. So if we check this documentation, you will see it there also, there is a third way of using this autocomplete to Egypt programmatically by yourself. And in that case, you would need to handle data searcher widget by yourself. But I'm going to show you this third way when we actually start implementing in creating our geofence application. For now, it's enough for you to know those two main ways of using autocomplete to support fragment and launching this autocomplete with any intent. So it's very easy as you can see, and that'll be all for this video. 14. Constrain Autocomplete Results: Hello there and welcome back. So in the previous videos, I've shown you two ways of implementing auto complete widget. So you saw our first way of implementing autocomplete support fragment in the other way by using activity to launch our auto complete widget. And of course, there is a third way of implementing a autocomplete programmatically and customizing it by ourselves. And we're going to talk about that third way when we actually start creating our geo fencing application. And you will see about that. And in this video, I wanted to show you how we can constrain and restrict the actual result which we are going to receive from our auto complete widget. So here if we open up this official documentation, you will see that there are multiple ways or for restricting or a limiting the actual result which we can receive on our auto complete widget. So what to constrain the results? We can, it was a this set location buyers function to prefer a results within the defined the region. Then we can use this set location restriction function to only show our results. So we think that they find the region. So as you can see this first function set location bias, we'll just prefer the results from one region. But if we use this set location restriction function, then it will limit basically the actual result which we can get. Then also we can use this set type filter, which we have already seen in the previous videos, where we can define what filter types so we can use to get the results from our autocomplete widgets. And of course, there is one more function named a set countries, which will allow us to basically eliminate the countries which we want to search from our autocomplete rigid and their countries must be passed as a two character with this ISO or 31, 66, 1 alpha 2 compatible country code. So while it's scroll down below, so you can see some examples here in this documentation. And here we can see a set location bias function. And inside we're passing a rectangular bounce object. And inside that where best singer to LatLng objects or two locations. So the first LatLng object in most cases here is represented by north or east point. And the second LatLng object is presented by Southwest point. And by choosing those two points, we can imagine in our header 2, we are drawing a rectangle to connect those two dots. And that way we can define a region R came. And then down below we have this example of using a set location restriction function and basically is the same as the previous example. But the main difference between those two function, between the set location bias and the set location restriction is that this set location bias function will just prefer the result from this region which we have specified and that this set location restriction of function, we'll align with the results from this specific region. Okay, so next let's scroll down below, and here we have our filter results by place time, So well, we can also filter auto-complete results to a specific place type. And then we can call our set type filter function to set the filter to use. And then we can pass the filter to a fragment or intent. And the down below we can see two examples or for using this set type filter with our autocomplete support fragment and with our intent. So we're now I'm going to open up Android Studio and we are going to apply this type filter to our autocomplete support fragment. So as you can see here down below, I'm going to call autocomplete fragment, then a set type filter in here I'm going to call a type filter. And here as you can see, we have multiple type field or a slight curve. Cities, geocode, address, establishment or regions in here, for example, we can choose address, and now let's run our app. So now let's click on our search widget here or on our auto complete widget in here. For example, if we type our Belgrade, as you can see, we're not going to see the actual city. Instead, we're going to see an address in here. For example, we can search some address in a Belgrade. And now as you can see this autocomplete, the widget is primarily focused on addresses and they're not cities as before. And of course now we can replace this with cities. And let's now open our app again. And now if we try and search here for Belgrade, for example, as you can see, it will display only the city and not the actual addresses. So there is only one more thing which I want to show you here. So as you can see here, we have specified that we want to be able to receive IDs and the names. Of course, we can specify some more fields. But for example, let's try and removing this name and let's see what will happen if we tried to click on one of those items from the list and what message we're going to see inside our logcat. Okay, so let's here type in search, for example, for Belgrade as well. So click here. And now as you can see, for the city, you're going to receive a null and for the ID you are going to receive a place ID. So if you want to see, for example, name, then you would need to specify that as a field here. And if you don't specify data field here, then you will not be able to retrieve that information for a places API. And of course now we can get back here and there, just undo. And of course we can use multiple fields like lat, long address, business status, ID, name, opening hours, phone number, and so on. And finally, I want to show you how you can filter results by a country. So if we scroll down below, we're going to see one simple example. So what or filter auto-complete results to up to five countries. We need to call set countries function to set the country code. And as you can see, this is just one example and we need to use those two character country codes. Example. Let me just use this function right here. So autocomplete fragment dot, dot set countries. And here as you can see, we can pass some multiple strings. So for example, here I can type RS, which is referring to my country, Serbia. And the now let me just start this application so I can show you that whenever we type some city, it will not show us the results of each and every city on the planet. Instead, it will show us only the results or the cities from my country. So here, as you can see, if I type per Berlin for example, and nothing will happen and we're not going to receive annual result because we have restricted our auto complete widget to only Serbia as a country. And here if I type are Belgrade for example. As you can see, we can see that so well now you might be wondering, why is this so important? Why is it important for us to actually restrict countries or a type filters or regions? Well, the first and main reason is because with this, with those location restrictions, with countries and so on, we can increase the overall performance of our autocomplete widgets. And also we can reduce the coast of these places. Api service. So for example, if we restrict our auto complete widget to only one country or two, maybe one region. Then whenever we search here in our auto complete widget, then we're going to spend less on our Places API service. And for example, if you don't restrict your auto complete widget with any country or location or even a type filter, then the overall performance of this auto complete widget will be lower. And of course, the cost of this service will increase. So those were the two main reasons why you should always restrict or limit your auto complete widget to certain countries or locations. And of course, type filters. And it's always a good practice to get the user's location before you actually implement the auto complete widget. And in that case, you can just use that user's location to set the limit or this restriction for auto complete widget. And that way you can increase the overall performance and you can reduce the cost of the service Savoir. That will be all for this video. 15. Get the Current Location: Hello there and welcome back. So in this video, I'm going to show you how to get the current place. So using a places as the k and also how you can discover the place at the devices currently reported location and examples of those places, our local businesses are points of interest in the geographical locations Savoir down below in this documentation, we can see that if we want to use this fine current place, some of these places client, then we need to declare this axis fine location permission. And there we also need to request a runtime permission for that. So while it's scroll down below, and here you can see the steps which we need to take in order to implement this functionality. So the first thing you need to check, if you have this permission and if you don't, you need to request the runtime permission for access. Final question. Then you need to create fine current place the request and the pass our list of place fields which you want to yours. Then you need to qualify and current place function and you need to pass a fine current place request from