Get Current Location of User in Your Flutter App | Flutter Geolocator 📍

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video let's fetch you just devise location and show the coordinates on the screen in just few simple steps so let's begin i have already created some boilerplate code for ui and currently it is running on my chrome browser and at the end of this video we will able to get the location by clicking on this get location button we will use geolocator package for all of the location related services so let's add this into perspective file make sure you use the latest version now it's time to implement device location page and this is a stateful widget that we have already created and here we have declared a location variable that will be displayed here and this is the basic ui that i have already created now we have to fetch the location by clicking on this get location button so first we need to import the geolocator package and here semicolon and now we have to create a function that will be called inside the on pressed and this is the complete function that will fetch the location i have copied it from the official documentation and now let me explain each of the things for you here we have declared two variables services enabled and permission in services involved we will assign the geological services involved this will check whether the location service is enabled or not if service is not involved then we will simply return the future error that location services are disabled so because you know always the location is not open some users can turn off their location so in that case we can also here open the location setting on the user device if location services is disabled and simply we will call the geolocator dot open location setting this will open the location setting on the user device and the permission we have assigned geolocator dot check permission that will get the current permission status of the device of the app from the device and if permission is denied then we will request the permission and again if permission is denied then we will return the error message that location permissions are denied so what if location services is denied forever then in that case we can simply return the error message that location permissions are permanently denied we can't request permission and if everything is okay then at the end we will return the geolocator dot get current position and this will return the position and from position we can simply get latitude and longitude now it's time to call the determine position function and store the position in a position variable so let's create a position variable position and inside the position let's store the value of position that is coming from the determine position function and now we need to update ui so let's call set state and inside set state let's set location to the position.latitude comma position.longitude now let's hot reload and see the output okay so let's click on this get location button and here we go we got allow and block option this is requesting the location and here we got our latitude and longitude it was very simple and in the url bar we can see that this site is using location and if we click on the detail of this site we can see that location is allowed so we have successfully fetched the position of user's device if you want to show the actual address then you can use geocoder package i will put the link up these packages in the description thanks for watching till end feel free to like and subscribe have a great day see you soon in the next video
Info
Channel: TDevelopers
Views: 1,563
Rating: undefined out of 5
Keywords: flutter, geolocator, flutter location, flutter google map, geocoding, location services, how to fetch location in flutter, live location flutter, geolocator flutter package, google location services, tdevelopers, dart, Get Current Location of User in Your Flutter App, location permission
Id: CBMbWIq7-vE
Channel Id: undefined
Length: 4min 32sec (272 seconds)
Published: Sun Jul 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.