onLocationChanged does not get called??

by hc » Sat, 07 Mar 2009 13:25:26 GMT

Sponsored Links

I have been struggling to get onLocationChanged called, but I'm not
sure it does not.
Here're my code

                criteria = new Criteria();

                String locationContext = Context.LOCATION_SERVICE;
                locationManager = (LocationManager)context.getSystemService

                String provider = locationManager.getBestProvider(criteria, 

                Location location = 
                locationManager.requestLocationUpdates(provider,0 ,

and ..... in the methods below, only onStatusChanged is being called,
and not onLocationChanged

     private final LocationListener locationListener = new
        public void onLocationChanged(Location location)
                Log.d("onLocationChanged","update now");

        public void onProviderDisabled(String provider)

        public void onProviderEnabled(String provider){
        public void onStatusChanged(String provider, int status, Bundle
                Log.d("Provider status changed", provider.toString());

here are permissions from my manifest

android:name="android.permission.ACCESS_WIFI_STATE" />
android:name="android.permission.ACCESS_COARSE_LOCATION" />
android:name="android.permission.ACCESS_FINE_LOCATION" />
android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.CAMERA" />

and I missing something ?
I have tried to add this line below requestLocationUpdate

Location location = locationManager.getLastKnownLocation(provider);
because I thought this might get me the last location just requested
from the requestLocationUpdate in the line before it, but it does not
help to retrieve the current location. It still retrieves the previous

onLocationChanged does not get called??

by hc » Sat, 07 Mar 2009 14:09:37 GMT

 an someone correct me if I'm wrong,

I checked the status in onStatusChanged. It shows
Makes sense since I'm indoor. But if I'm indoor, I want it to change
the provider to network.

So here's how I'm doing it.
1) When I try to location myself, I will use GPS as my provider.
2) if GPS signal is available, onLocationChanged will be called, and
that's done!
3) if onLocationChanged is not called, but onStatusChanged is called,
I check the status or my provider
4) if status of my GPS provider showed in onStatusChanged is
TEMPORARILY_UNAVAILABLE, then I'll change my provider to network
5) to change my provider from GPS to NETWORK, I add the following line
inside onStatusChanged

location.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0 ,

This seems to be working for me now.. finally.
But I'm wondering if this is the best way to do it. Feels a bit hacky

On Mar 7, 1:25pm, hc <> wrote:

Sponsored Links

Other Threads

1. Payment options for Android Market


Not long ago, I read a post at
about coming updates to the Android Market. These updates had to do
with expanded options for billing beyond the current ones (free vs.
paid). I was wondering if anyone had any idea when these additional
options will be available. Google Checkout has a new capability for
monthly subscriptions, which is in beta. I assume the updates to
Android Market will take place once the new Google Checkout feature is
out of beta. I also assume the time table for this particular feature
coming out of beta will be shorter than the beta period for, say,
Gmail. Any insights are appreciated.


2. Midi file problem with sonivox player

Hi All,

i am facing some chopping sound while playing the midi file.

some of the instruments are not getting played while playing the  midi file.

i have attached the sample midi file which is having 10 instruments in it.
while playing it after the 15th second the cello instrument is supposed to
play and it is not playing.

i tested it in Anvil studio on windows and i am able to play the complete
file without any issues.

i just want to know is it the limitation of the EAS_Library or i need to
improve the Sonivox code.



3. Separating Widget from main Application

4. is there any browser that could be used on Android?

5. ContextMenu for ListView

6. Simplify Media Equivalent

7. Android application trying out rss feed read using Rome. Getting exception ExceptionInInitializerError