How to Get Current Location on Google Map in Android Studio | Step by Step Google Maps Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] .com guys in this video I will show you how you can get the current location of device and show it in on the Google Maps so in our previous video we implemented the Google Maps in this application and if I show you this so you can see here we have implemented this uh kind of map and we are showing the marker here so in this video we will get the current location of device and we will also request a permission the file location permission so let's start location permission so let's start our tutorial first of all we need to add a dependency and as you can see here we have already added the maps to edit the maps dependency so we need to copy it from here like the commodity or Ctrl D so it will duplicate it here so I will just simply type location here and we need to add this to okay change to 20.0.0 and click on sync now this is the latest version of this dependency and I will close this go to the Manifest and here we need to add two permissions use permission use permission and the first one is course location and the second one is fine location so okay and these permissions are added and now we will close the Manifest file and first of all I will create a permission code here so private final integer and I will name it fine permission chord and I will be equal to one and I will need the location variable here so I will call it okay and I will need the fused use location drawing and I will name it purification for your clients okay and now what I will do I will just simply initialize this fuse location client is equal to location Services dot get view location and I will pass the context of this activity okay now I will I will call a letter here get lost okay and we will create this method here private void at last location at last location and inside this get lost location we will get the current location okay so I will create a task here task which will be the type of location I will name a task is equal to so it will be equal to okay and I'll remove this fused provider fuse location by client dot get last occasion and as you can see here we we got an error so if you click on this and click on this Red Bull episode simply click on this add permission check so it will add the permission check and what does this permission chip do it checks for the fine location permission if it is not granted and okay it is also checking for this access course location permission so we will uh we will get the file location permission if the permission is not granted so to get our permission simply type activity compare with a request formation pass the context of this activity new string add this we will pass the Manifest dot permission Dot find location and we will pass the find information code here okay so what we are doing we are requesting the runtime permission from the user now we will use a task so simply I will add a success listener on this so add on success listener and new on success listener and I will check for the location check for the location if the location here is not equal to null application is not equal to null then we will assign this location to our current location so current location is equal to location and I will add a semicolon here and I need to uh get this support fragment from there you can save this if statement okay and what is the issue here on success user or okay now this I will just pass the main activity dot this okay and write a method draw here on request permissions so I will check if a request code is equal to find permission for if the permission code is equal to our permission code then I will also check here if so check here if Grant result and Grant result dot equal to okay I think we need to add dot length here yeah manager dot permission granted then what we will do we will grid will get the location so I will just simply copy it from here and I will also call it here and if the user didn't allow the permission so we will show our doors to the user first create first and um hear the message like location information permission is denied please know the permission to assist okay I will just simply ask you to allow the permission okay that's it guys so now what we will do we are passing the latitude and longitude uh hard coded here so I will just simply remove this and what I will do I will pass the current rotation dot get latitude and current location dot get longitude okay so now I will just simply call it my location okay okay so as you can see here I know my Google Maps to access this little device I know my Google Maps to access this little device location so I will just simply click on dot hello and it will show at all location permission is denied please another permission so if I close the application and I open it again okay let me open it again from here very much for the permission so I will just simply uh select the first one while using the app now it will get my current location and currently I I'm in Pakistan and as you can see here I'm in this level right now so this is my current location so that's how you can get the device current location and show it in on the Google Map in your Android application so that's it for this video guys and if you like this video please share this video with your friends and make sure you are subscribed to my channel and the bell notification option is on so you won't miss the upcoming videos
Info
Channel: CodingZest
Views: 33,598
Rating: undefined out of 5
Keywords: CodingZest, how to get current location on google map in android studio, how to get current location in android studio, how to get current location in google map android, how to get current location in android studio using google map, get current location android studio google maps, get current location android studio, get current location on map in android studio, get current location latitude and longitude in android studio, google maps current location android studio
Id: XimcwP-OzFg
Channel Id: undefined
Length: 8min 4sec (484 seconds)
Published: Thu Mar 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.