Solved

get curent GPS location

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
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.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

765 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