How To Program Android Apps: Android Geolocation Tutorial (Android Location Manager)

Android

Video is ready, Click Here to View ×


http://www.frameworktv.com | LearnToProgram is now Framework. Visit and join for free daily videos teaching digital skills like coding and design.

SUBSCRIBE TO THE FRAMEWORK CHANNEL
http://www.youtube.com/subscription_center?add_user=UC4msOaZNMfPwMe_ztV5jFH

SUBSCRIBE TO OUR EMAIL LIST (LEARN FOR FREE!)
http://www.frameworktv.com/?src=YOUTUBE

Many popular Android applications use the Android location manager to track the user’s location as they move with their Android device. This…

30 thoughts on “How To Program Android Apps: Android Geolocation Tutorial (Android Location Manager)

  1. I followed the video very well and then added Roger Garrett's suggestion but I still can not get any coordinates to show up when I am running this on a Note 4. Can anyone help?

  2. Um yeah when I type lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); a red line appears underneath it and it freaking says to add a permission code check. This is what it puts:
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    // TODO: Consider calling
    // ActivityCompat#requestPermissions
    // here to request the missing permissions, and then overriding
    // public void onRequestPermissionsResult(int requestCode, String[] permissions,
    // int[] grantResults)
    // to handle the case where the user grants the permission. See the documentation
    // for ActivityCompat#requestPermissions for more details.
    return;
    What am I supposed to do exactly? (Oh and the app doesn't even run the way it's supposed to. The app opens but when I go to import the lat and long, nothing happens. Help would be nice. Thank you.

  3. Thanks for this video, very helpful for my program. I just want to ask, is it needed to have a Google Map Activity to be able to access the capability of ACESS_FINE_LOCATION??
    Thanks for the answer. . . . . .

  4. Hi, its about the geolocation manager video in your channel i like its content but i need to save those locations to a file which will be stored locally in my phone can you help me create a code that will give permission to do that. thanks

  5. How to get Location using latitude and latitude .i have added following code to get address
    List<Address> addresses = geocoder.getFromLocation(77.5667, 12.9667, 1);

    but i am getting addresses.size()=0

  6. Nice Video !!!! But just to point out that you can write inner class inside the method in Java but you need to declare that inner class first and then use it. 
    So it should be like 
    public void onCreate( ….){
        class MyInnerClass{
        // inner class body
        }
       // now i am free to user MyInnerClass
       new MyInnerClass().callInnerClassMethod();
    }

  7. It does show new gps location when I move but beacuse it is called from "Location changed" it does not show anything before I move. I have tried to implement the "setText" everywhere else but nothing works. How do we get gps data even if we do not move?

  8. It should be noted that when you run this app on an actual device the OnLocationChanged event handlers will probably NOT initially get hit, and it will appear that nothing is happening. That's because your device already has its "current" location and, if you're just sitting there with the device in your hand, it's not changing. So the OnLOcationChanged method won't get called and the LAT and LONG values will not show on the device.

    I recommend adding the following code to the onCreate method, right after you set up the LocationManage, as follows:

            Location lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (lastLocation != null)
            {
                textLatitude.setText(Double.toString(lastLocation.getLatitude()));
                textLongitude.setText(Double.toString(lastLocation.getLongitude()));
            }

    By doing that you'll see whatever is the current lat/long values right when you start up the app, and then, as you move around, it will begin to update.

  9. App crashes as soon as I send location to it. I got following error in Logcat. Well,if I uses Log.d to print locations and it shows them in Logcat, but if I try to fetch the location on UI it shows me following error.

    05-10 18:55:02.234: E/AndroidRuntime(948): FATAL EXCEPTION: main
    05-10 18:55:02.234: E/AndroidRuntime(948): java.lang.NullPointerException
    05-10 18:55:02.234: E/AndroidRuntime(948): at android.content.ContextWrapper.getPackageName(ContextWrapper.java:135)
    05-10 18:55:02.234: E/AndroidRuntime(948): at android.location.GeocoderParams.<init>(GeocoderParams.java:50)
    05-10 18:55:02.234: E/AndroidRuntime(948): at android.location.Geocoder.<init>(Geocoder.java:83)
    05-10 18:55:02.234: E/AndroidRuntime(948): at com.example.geoloc.mycurrentlocation.onLocationChanged(MainActivity.java:49)
    05-10 18:55:02.234: E/AndroidRuntime(948): at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:255)
    05-10 18:55:02.234: E/AndroidRuntime(948): at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:184)
    05-10 18:55:02.234: E/AndroidRuntime(948): at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:200)
    05-10 18:55:02.234: E/AndroidRuntime(948): at android.os.Handler.dispatchMessage(Handler.java:99)
    05-10 18:55:02.234: E/AndroidRuntime(948): at android.os.Looper.loop(Looper.java:137)
    05-10 18:55:02.234: E/AndroidRuntime(948): at android.app.ActivityThread.main(ActivityThread.java:5103)
    05-10 18:55:02.234: E/AndroidRuntime(948): at java.lang.reflect.Method.invokeNative(Native Method)
    05-10 18:55:02.234: E/AndroidRuntime(948): at java.lang.reflect.Method.invoke(Method.java:525)
    05-10 18:55:02.234: E/AndroidRuntime(948): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    05-10 18:55:02.234: E/AndroidRuntime(948): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    05-10 18:55:02.234: E/AndroidRuntime(948): at dalvik.system.NativeStart.main(Native Method)
    05-10 18:55:05.094: E/InputDispatcher(274): channel '41a301a0 com.example.geoloc/com.example.geoloc.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!

    Plzzzz,,, Helpppp…..

  10. Hi, I cannot thank you enough for this. I was stuck with this thing for a week!! I tried so many different approaches including a ScheduledExecutorService but it would just crash!! This one worked fine. Thanks a lot!

  11. Thank you so much for the tutorial, works great.
    The only problem I have is that when I run the app, its takes forever for the latitude and longitude to be displayed. Is there any way I can make it appear quicker or is that just how it work? Any help would be great. 

Leave a Reply

Your email address will not be published. Required fields are marked *