Android Get Current Location Continuously | Location Service | Fused Location Provider API

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ก.ย. 2024
  • Android Get Current Location Continuously | Location Service | Fused Location Provider API
    In this tutorial, we will implement a foreground location service which will give us continuous location updates using the fused location provider API.
    For more exciting android tutorials, please subscribe to my TH-cam channel and hit the bell icon for notifications.
    android location service, android track location, android location updates, android location service android, android get current location continuous, android location periodically, chirag kachhadiya, kachhadiya chirag, android get current location, get current location android, get current location android studio, android studio get current location, android get current location tutorial, android studio location service, location service in android, location service android

ความคิดเห็น • 137

  • @vinitpatra7462
    @vinitpatra7462 2 ปีที่แล้ว +6

    [Important] Android permissions is updated and for API 29 or higher, "ACCESS_BACKGROUND_LOCATION" permission is required as well along with FINE and COARSE location permissions.

  • @rahul08yadav
    @rahul08yadav 4 ปีที่แล้ว +3

    Thank You Sir. You code so clean please continue making such video and try to add audio explanation if possible. You really helped me.

  • @adityasinghrajawat7344
    @adityasinghrajawat7344 4 ปีที่แล้ว +5

    Very Good!!!
    But just a suggestion for you......You should speak while making tutorials.

  • @Nags343
    @Nags343 29 วันที่ผ่านมา +1

    Thanks a lot it worked

  • @WolfSkinFull
    @WolfSkinFull 4 ปีที่แล้ว +1

    Огромная человеческая благодарность!

  • @jigin100
    @jigin100 2 ปีที่แล้ว

    Thanks for the turorial. It helps me a lot on my project.

  • @didieralejo
    @didieralejo ปีที่แล้ว

    Great job! Thanks for your explanation, it was very helpful.

  • @sandyhuang8322
    @sandyhuang8322 3 ปีที่แล้ว +1

    oh man , you save my day and my life , appreciated , thank you ! do you have tutorial about Google Fit?

  • @hexafgamer
    @hexafgamer 2 ปีที่แล้ว +1

    its perfect bro thank you so much.

  • @bhagyshrikadam7088
    @bhagyshrikadam7088 3 ปีที่แล้ว +2

    thank you sir

  • @pushanpaul1305
    @pushanpaul1305 3 ปีที่แล้ว +1

    So far the most helpful location update video

    • @bodieernest6546
      @bodieernest6546 3 ปีที่แล้ว

      I know im randomly asking but does someone know a way to log back into an Instagram account?
      I was dumb forgot the login password. I would appreciate any help you can offer me.

    • @dravenomar4032
      @dravenomar4032 3 ปีที่แล้ว

      @Bodie Ernest Instablaster :)

    • @bodieernest6546
      @bodieernest6546 3 ปีที่แล้ว

      @Draven Omar i really appreciate your reply. I found the site thru google and Im in the hacking process now.
      Takes quite some time so I will reply here later with my results.

    • @bodieernest6546
      @bodieernest6546 3 ปีที่แล้ว

      @Draven Omar it worked and I finally got access to my account again. I am so happy!
      Thank you so much, you saved my account :D

    • @dravenomar4032
      @dravenomar4032 3 ปีที่แล้ว

      @Bodie Ernest glad I could help :D

  • @bvr9954
    @bvr9954 3 ปีที่แล้ว +1

    This works great. Thank you so much

  • @nickolajarjous2639
    @nickolajarjous2639 3 ปีที่แล้ว +1

    great tutorial

  • @jaa70
    @jaa70 4 ปีที่แล้ว +2

    Sir, thank you very much !!!, one question: if I restart the phone, the app will start too? if not, how can I get that ?

    • @amenmoipushi8821
      @amenmoipushi8821 3 ปีที่แล้ว

      Set a broadcast receiver to know when the phone has been rebooted then if it has, start the location service.

  • @m-coders
    @m-coders 3 ปีที่แล้ว

    Thanks sir Its very helpful to me

  • @muhammadabdullah3181
    @muhammadabdullah3181 3 ปีที่แล้ว +1

    Good job Man 😊

  • @AmanKumar-ec6bz
    @AmanKumar-ec6bz ปีที่แล้ว

    thanks bro save my time

  • @ajayvamsee7508
    @ajayvamsee7508 3 ปีที่แล้ว +1

    Well superb but why not you provide project repo

  • @jayantdhingra4863
    @jayantdhingra4863 4 ปีที่แล้ว +1

    Thanku for this tutorial.
    Also plzz make video on google fit

  • @danny_phantomwalker8418
    @danny_phantomwalker8418 3 ปีที่แล้ว +1

    I have a question - Instead of getting Lat n Long in Log.d, can u show me how to display it on the app screen in Textview? I can't seem to get it done correctly. Other than that, great tutorial, Just wish you would explain, atleast as notepad writings or something. Thanks for the video!

    • @ziedorabi7534
      @ziedorabi7534 3 ปีที่แล้ว

      I'm stuck at this as well , any progress ?

    • @kadirbozkurt2412
      @kadirbozkurt2412 2 ปีที่แล้ว

      @@ziedorabi7534 did you solve? if you did please tell me how

  • @officefineoutput379
    @officefineoutput379 3 ปีที่แล้ว

    Useful Tutorial

  • @MrZiko1975
    @MrZiko1975 4 ปีที่แล้ว +1

    Good job! But it's not fully completed, we have to get result in activity/fragment/custom view. What channels do you use for that? EventBus or something more modern?

    • @chiragkachhadiya
      @chiragkachhadiya  4 ปีที่แล้ว +1

      You can use intent service or local broadcast manager as well.

  • @thangphamduc4085
    @thangphamduc4085 3 ปีที่แล้ว

    Thanks a lot. It's very good.

  • @noormohammad8859
    @noormohammad8859 3 ปีที่แล้ว

    nice work.. very workfull

  • @jithendrasai
    @jithendrasai 4 ปีที่แล้ว +1

    nice tutorial, bro

  • @HardikPatel-zp3hc
    @HardikPatel-zp3hc 3 ปีที่แล้ว +2

    I have created tracking app which runs perfectly in android 7 in background but not running in 8+
    Any solution?

  • @surenrajp6228
    @surenrajp6228 3 ปีที่แล้ว +1

    What android studio you are using bro... it was awesome??

  • @Roraluv
    @Roraluv 3 ปีที่แล้ว

    Excellent...

  • @akshayrajput1586
    @akshayrajput1586 3 ปีที่แล้ว +1

    how this app is getting location in the background when we allow it "only while using the app" location permission
    also, I have noticed that it's not getting location in background after few seconds

  • @pgaurav72
    @pgaurav72 4 ปีที่แล้ว +3

    Thank you Sir!
    The code helped me a lot.

  • @creativearts4917
    @creativearts4917 10 หลายเดือนก่อน

    how do we pass this data to main activity means the one from which the location service call ran

  • @syedasadalizaidi55
    @syedasadalizaidi55 3 ปีที่แล้ว +1

    Yo bro you saved my life and job lmao

  • @mckrecior5737
    @mckrecior5737 8 หลายเดือนก่อน +1

  • @musicwell3940
    @musicwell3940 4 ปีที่แล้ว +2

    Can u please make a tutorial on Google fit Integration

  • @HarpreetSingh-cl1sp
    @HarpreetSingh-cl1sp ปีที่แล้ว

    How i pass the location double value co-ordinate to other activity and set it to text view. PLEASE REPLY

  • @rakeshpavanmudidana
    @rakeshpavanmudidana ปีที่แล้ว

    Sir location share is working in version 13 in background also but that app is not working in any other version like lower then Android 13 version please give me a solution for this sir,🥺

  • @barriosraphael4
    @barriosraphael4 2 ปีที่แล้ว

    Great tutorial!!!!
    does it work in background?

  • @reyzanata8093
    @reyzanata8093 4 ปีที่แล้ว +2

    hi how if i want to add marker on Latlng and pass the data in to the components thanks

    • @DevKumar-ey6fh
      @DevKumar-ey6fh 3 ปีที่แล้ว

      You got solution?
      Because I'm facing same problem.

  • @ahmadelmasri9702
    @ahmadelmasri9702 2 ปีที่แล้ว

    Thanks a lot man !

  • @shreyanshjain954
    @shreyanshjain954 3 ปีที่แล้ว

    sir after using this code the accuracy of location is not fine...this code uses which feature .. GPS provider or Network Provider??...I think gps will have more accuracy

  • @sachinmurkuteshorts
    @sachinmurkuteshorts 3 ปีที่แล้ว +1

    06:19 to 06:21 there is a problem in the code line numbers maybe you imported something but the video does not show that

  • @vsp4
    @vsp4 2 ปีที่แล้ว

    Thanks

  • @praveshbudhathoki736
    @praveshbudhathoki736 4 ปีที่แล้ว +1

    I got error in (Constants.LOCATION_SERVICE_ID), location-service-id is not recognized. help plzz

  • @teacup2633
    @teacup2633 3 ปีที่แล้ว

    Thanks, can you make tutorial to get Country \ City name?

  • @Joannes25
    @Joannes25 2 ปีที่แล้ว

    excelente!!!!!

  • @sandeepkumar-yp6sl
    @sandeepkumar-yp6sl 2 ปีที่แล้ว

    This code is not working on above API level 28.... please help me sir

  • @Mardiyansahok
    @Mardiyansahok 3 ปีที่แล้ว

    Thank you Sir...but how to add iduser login on the location service?

  • @thanhnguyenminh5723
    @thanhnguyenminh5723 4 ปีที่แล้ว

    verry nice

  • @suryaagungputra298
    @suryaagungputra298 4 ปีที่แล้ว +1

    can u tell me what theme u install for ur android stud please ?

    • @chiragkachhadiya
      @chiragkachhadiya  4 ปีที่แล้ว

      It's a plugin for android studio called Material Theme UI.

  • @AbdulSamad-yu1zn
    @AbdulSamad-yu1zn 3 ปีที่แล้ว

    Hii Dear all how are you? I hope you all will be fine.
    I am facing null lat/long issue as i am using fusedlocationproviderclient...
    If mobile GpS button is enabled then i get location.. if i disable or reEnable it then i get null location.. if if i close or open app again and again
    Is there any other service or anything instead of this which works fine??

  • @apurvadiwe7237
    @apurvadiwe7237 ปีที่แล้ว

    Working fine with Android 8,9
    But how to get background location above android 10?

    • @apurvadiwe7237
      @apurvadiwe7237 ปีที่แล้ว

      It works fine till 1-2 min after that it stops getting the location.

    • @syedaamna6086
      @syedaamna6086 ปีที่แล้ว

      @@apurvadiwe7237 When I open other applications like facebook or watsapp, it stops giving location updates....

  • @Kshashiranjan
    @Kshashiranjan 7 หลายเดือนก่อน

    Hi...Anyone can help to get the someone mobile location through link or by hidden link?

  • @kovgergox
    @kovgergox 3 ปีที่แล้ว +1

    Service stops after app is not in focus in my case :(

    • @HungVu-dm6xc
      @HungVu-dm6xc 3 ปีที่แล้ว

      how long does the service take to stop in your case? I also encountered the same case. Do you know the cause and how to fix it?

    • @syedaamna6086
      @syedaamna6086 ปีที่แล้ว

      Did u manage to resolve this issue>?

  • @kamilpuchaa5138
    @kamilpuchaa5138 3 ปีที่แล้ว

    This may not work correctly when the app work in background. Simply not showing new updates, on the newest Android...

    • @marceloaguilarsanchez9414
      @marceloaguilarsanchez9414 8 หลายเดือนก่อน

      yeah, that's the problem, the code works, but in lower versions of 7, that's a problem that I found in my androrid 11, it doesn't work in foreground :c

  • @zeeshanalimannur5704
    @zeeshanalimannur5704 2 ปีที่แล้ว

    I'm getting a delay=8000 ms and i don't know what to do I've searched online but couldn't get any help please help me out

  • @obadaqafisheh9185
    @obadaqafisheh9185 4 ปีที่แล้ว +3

    can't get location updates after kill the app!!!

  • @Mechas1123
    @Mechas1123 4 ปีที่แล้ว

    Nice code !!!!

  • @TheAftermath
    @TheAftermath 3 ปีที่แล้ว

    Sorry sir, are Fused Location Provider APIs free to use?
    Aren't they from Google Play Services? So Are Google Play Services APIs free to use?

  • @shantanudixit306
    @shantanudixit306 2 ปีที่แล้ว

    the code is not working in android 11v when app is running in background mode

  • @JUANFELIPENIGANEZALIAGA
    @JUANFELIPENIGANEZALIAGA 3 ปีที่แล้ว

    thanks but how can i add it to a textview please

  • @Erwinsmith94040
    @Erwinsmith94040 2 ปีที่แล้ว

    I appreciate your code but its too complicated for begineers

  • @numanbhati7115
    @numanbhati7115 4 ปีที่แล้ว +1

    Sir please make a video on tablayout with only single fragment

    • @chiragkachhadiya
      @chiragkachhadiya  4 ปีที่แล้ว

      But if you want only single fragment or screen then what is the meaning of tab layout since tab layout is used when you want to display multiple screens in single activity or something similar to that.

    • @numanbhati7115
      @numanbhati7115 4 ปีที่แล้ว

      @@chiragkachhadiya sir you are right make Tablayout logic video

    • @numanbhati7115
      @numanbhati7115 4 ปีที่แล้ว

      @@chiragkachhadiya please sir please sir

    • @chiragkachhadiya
      @chiragkachhadiya  4 ปีที่แล้ว

      Here it is: th-cam.com/video/ajVVjuOSlV4/w-d-xo.html

    • @numanbhati7115
      @numanbhati7115 4 ปีที่แล้ว +2

      Thank you for your reply sir this video is very helpful for me

  • @zandronarvaza6891
    @zandronarvaza6891 4 ปีที่แล้ว

    Is it possible to jampack a volley method on the service class ?

    • @chiragkachhadiya
      @chiragkachhadiya  4 ปีที่แล้ว

      Yes.

    • @zandronarvaza6891
      @zandronarvaza6891 4 ปีที่แล้ว

      @@chiragkachhadiya It crashes the app when I put volley inside. Can you give me a hand please :(

  • @maadmayya2550
    @maadmayya2550 4 ปีที่แล้ว

    Can you make a lap with aws ?

  • @Shafi10111
    @Shafi10111 4 ปีที่แล้ว

    how would i call those latitude longitude values in another activity? any help would be appreciated

    • @anaslakhani
      @anaslakhani 3 ปีที่แล้ว

      use broadcast reciever

    • @DevKumar-ey6fh
      @DevKumar-ey6fh 3 ปีที่แล้ว

      @@anaslakhani hey can you help me how to set text for the value of lat and longt and keep updating it as the value be updated.

  • @hoannguyen9381
    @hoannguyen9381 3 ปีที่แล้ว

    how to up location continuously to firebase
    bro????

  • @chchandrasekhar5575
    @chchandrasekhar5575 8 หลายเดือนก่อน

    and background also

  • @dimasoktanugraha9573
    @dimasoktanugraha9573 4 ปีที่แล้ว

    great tutorial sir. i've code your tutorial in kotlin, but when i click button stop location update, in my Log still get location update. is there any wrong?

  • @chchandrasekhar5575
    @chchandrasekhar5575 8 หลายเดือนก่อน

    I'm not getting locations when the app is killed

  • @ayushikannojia9495
    @ayushikannojia9495 3 ปีที่แล้ว

    Hey sir thank u for this video... Plz tell me how to save this latítude and longitude on database using postgreaql

  • @warkadang317
    @warkadang317 3 ปีที่แล้ว

    sir i have issue how to show that lat and long in activity updated

    • @DevKumar-ey6fh
      @DevKumar-ey6fh 3 ปีที่แล้ว

      Have you got, because I'm facing same problem.

  • @safatelli4152
    @safatelli4152 3 ปีที่แล้ว

    how can we make it working in background please ?

  • @viralgohil6616
    @viralgohil6616 3 ปีที่แล้ว

    Thankyou sir But not working not getting latlog

  • @ectechzone4769
    @ectechzone4769 3 ปีที่แล้ว

    not working above api24 . kindly update what to do

    • @Shivam-kz2dg
      @Shivam-kz2dg ปีที่แล้ว

      Include access coarse location , access background location

  • @subhadipbera1456
    @subhadipbera1456 3 ปีที่แล้ว

    SIR it doesn't work perfectly, plz help me...

  • @kadirbozkurt2412
    @kadirbozkurt2412 2 ปีที่แล้ว

    How do we send result to MainActivity? Please someone help.

  • @user-pv7ko9nk2q
    @user-pv7ko9nk2q 3 ปีที่แล้ว

    Не хочет показывать координаты

  • @surenrajp6228
    @surenrajp6228 3 ปีที่แล้ว +1

    bro source code ??

  • @my_love_sanatan
    @my_love_sanatan 2 ปีที่แล้ว

    not working android 10

  • @levihuibers5463
    @levihuibers5463 3 ปีที่แล้ว

    Fucking legend

  • @junaciz2409
    @junaciz2409 3 ปีที่แล้ว

    give me aplication,please

  • @navinhariharan6097
    @navinhariharan6097 3 ปีที่แล้ว

    Hey! Could I get the source code?

  • @chirujc
    @chirujc 4 ปีที่แล้ว

    location updates are stopped, when the app is killed from background

    • @khalilsnoussi8559
      @khalilsnoussi8559 4 ปีที่แล้ว

      you can't get location updates when the application stops, that's very normal

    • @chirujc
      @chirujc 4 ปีที่แล้ว

      @@khalilsnoussi8559 I completely agree with you. But my requirement is getting location updates, even if the app is killed or background

    • @khalilsnoussi8559
      @khalilsnoussi8559 4 ปีที่แล้ว

      @@chirujc i understood you, i had similar idea on my current project but in my case i needed notifications to show up even if the application wasnt working in the background and was very disappointed, actually notifications can't popup unless the actual application is working in the background you can test it with facebook or youtube apps.

    • @chirujc
      @chirujc 4 ปีที่แล้ว

      @@khalilsnoussi8559 but I believe, there is a way. Working on that, I will update you, once I have working example.

    • @chirujc
      @chirujc 4 ปีที่แล้ว

      @@khalilsnoussi8559 you can get location notifications, even if the app is killed from background . Here are the code changes to get it work
      instead of calling
      LocationServices.getFusedLocationProviderClient(this).requestLocationUpdates(locationRequest,locationCallback, Looper.getMainLooper());
      startForeground(Constant.LOCATION_SERVICE_ID,builder.build());
      use
      LocationServices.getFusedLocationProviderClient(this).requestLocationUpdates(mLocationRequest, getPendingIntent());
      and
      private PendingIntent getPendingIntent() {
      Intent intent = new Intent(this, LocationUpdatesIntentService.class);
      intent.setAction(LocationUpdatesIntentService.ACTION_PROCESS_UPDATES);
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
      return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      }

      In service class
      @Override
      protected void onHandleIntent(Intent intent) {
      if (intent != null) {
      final String action = intent.getAction();
      if (ACTION_PROCESS_UPDATES.equals(action)) {
      LocationResult result = LocationResult.extractResult(intent);
      if (result != null && result.getLocations()!=null) {
      double latitude = result.getLastLocation().getLatitude();
      double longitude =result.getLastLocation().getLongitude();
      Log.d(TAG,"LOCATION UPDATE: "+latitude+" "+ longitude);
      // sending data to popup notification, in my case, created static method sendNotification() in Utils class
      Utils.sendNotification(this, ""+Utils.getLocationLatitude(this)+", "+Utils.getLocationLongitude(this) + ": " + DateFormat.getDateTimeInstance().format(new Date()));

      }
      }
      }
      }
      In Utils class, add the following method
      static void sendNotification(Context context, String notificationDetails) {
      // Create an explicit content Intent that starts the main Activity.
      Intent notificationIntent = new Intent(context, MainActivity.class);
      notificationIntent.putExtra("from_notification", true);
      // Construct a task stack.
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
      // Add the main Activity to the task stack as the parent.
      stackBuilder.addParentStack(MainActivity.class);
      // Push the content Intent onto the stack.
      stackBuilder.addNextIntent(notificationIntent);
      // Get a PendingIntent containing the entire back stack.
      PendingIntent notificationPendingIntent =
      stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
      // Get a notification builder that's compatible with platform versions >= 4
      NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
      // Define the notification settings.
      builder.setSmallIcon(R.mipmap.ic_launcher)
      // In a real app, you may want to use a library like Volley
      // to decode the Bitmap.
      .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
      R.mipmap.ic_launcher))
      .setColor(Color.RED)
      .setContentTitle("Location update")
      .setContentText(notificationDetails)
      .setContentIntent(notificationPendingIntent);
      // Dismiss notification once the user touches it.
      builder.setAutoCancel(true);
      // Get an instance of the Notification manager
      NotificationManager mNotificationManager =
      (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      // Android O requires a Notification Channel.
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      CharSequence name = context.getString(R.string.app_name);
      // Create the channel for the notification
      NotificationChannel mChannel =
      new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_HIGH);
      // Set the Notification Channel for the Notification Manager.
      mNotificationManager.createNotificationChannel(mChannel);
      // Channel ID
      builder.setChannelId(CHANNEL_ID);
      }
      // Issue the notification
      mNotificationManager.notify(0, builder.build());
      }

  • @SKREFI
    @SKREFI 3 ปีที่แล้ว

    Source code please?

  • @luishectormonterosantos1215
    @luishectormonterosantos1215 4 ปีที่แล้ว

    Error Android Q+

  • @VINAYSHARMA2323
    @VINAYSHARMA2323 ปีที่แล้ว

    Source code

  • @ssanjay3793
    @ssanjay3793 29 วันที่ผ่านมา

    source code

  • @user-vv4uq4xs8f
    @user-vv4uq4xs8f 4 ปีที่แล้ว

    Well, nice, but in 2020 Kotlin is the better choice....

  • @hackaman9752
    @hackaman9752 3 ปีที่แล้ว

    i need the code bruhhhhhhhhh

  • @ankeshpandey3630
    @ankeshpandey3630 4 ปีที่แล้ว

    Check instagram, DM you

  • @kuteslekkeropzeg
    @kuteslekkeropzeg ปีที่แล้ว

    Is it possible to download the code ?

  • @alberto3514
    @alberto3514 2 ปีที่แล้ว

    if (service.foreground) //Always False
    NotificationCompat.Builder //Dont show notifications
    Background, dont work

  • @samseleven1
    @samseleven1 3 ปีที่แล้ว

    This works great. Thank you so much