Solved

get curent GPS location

Posted on 2016-11-21
1
22 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

First off, some of you reading this are already thinking there is an error in the title. It really should be Kindle Fire versus OTHER Android tablets. That's because the Amazon Kindle Fire IS an Android tablet. Well, it is and it's not. It's running…
This is an explanation of a simple data model to help parse a JSON feed
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.

707 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

16 Experts available now in Live!

Get 1:1 Help Now