Solved

get curent GPS location

Posted on 2016-11-21
1
54 Views
Last Modified: 2016-11-25
Hello!
I need to display current user location in my MapFragment.

I try to use this code found on net:

        LocationManager locationManager;
        locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String provider = locationManager.getBestProvider(criteria, true);
        Location location = locationManager.getLastKnownLocation(provider);
        locationManager.requestLocationUpdates(provider, 20000, 0, this);

but my application crash. He stop running before displaying anything.

The problem is here :

        Location location = locationManager.getLastKnownLocation(provider);
        locationManager.requestLocationUpdates(provider, 20000, 0, this);

What I do wrong? This is my first android application.
0
Comment
Question by:ginsonic
1 Comment
 
LVL 16

Accepted Solution

by:
Chris Harte earned 500 total points
ID: 41897457
Are you implementing the locationListener? Here is an article I wrote on that particular problem.
https://www.experts-exchange.com/articles/22439/The-old-Android-LocationListener.html

The next problem you will have is that google are trying to deprecate the locationListerner and force everybody to use the location API instead.
https://www.experts-exchange.com/articles/27099/The-new-Android-LocationApi-and-permissions.html
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Xamarin 10 44
Samsung Android Marshmallow + autostart apps on boot 7 98
Windows Tool to Build Android and iOS App 3 50
RTSP blocked by AT&T? 11 26
Android SDK is used for creating an android software application. It includes document and tools which are necessary to develop applications with java. In fact Android SDK is harder than other software infrastructure, because there is a virtual devi…
A short article about problems I had with the new location API and permissions in Marshmallow
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now