onLocationChanged does not get called??

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


Sponsored Links
 Hi,

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

                criteria = new Criteria();
                criteria.setAccuracy(Criteria.ACCURACY_FINE);
                criteria.setPowerRequirement(Criteria.POWER_LOW);
                criteria.setAltitudeRequired(false);
                criteria.setBearingRequired(false);
                criteria.setSpeedRequired(false);
                criteria.setCostAllowed(true);

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

                String provider = locationManager.getBestProvider(criteria, 
true);

                Location location = 
locationManager.getLastKnownLocation(provider);
                locationManager.requestLocationUpdates(provider,0 ,
100.0f,locationListener);

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

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

        public void onProviderDisabled(String provider)
        {
                Log.d("onProviderDisabled",provider.toString());
        }

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

here are permissions from my manifest

    <uses-permission
android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission
android:name="android.permission.READ_PHONE_STATE"/>
    <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
location
--~--~---------~--~----~------------~-------~--~----~



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
TEMPORARILY_UNAVAILABLE for my GPS.
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.removeUpdates(locationListener)
location.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0 ,
100.0f,locationListener);

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 <honch...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Installing Android on different Handsets than G1?

Hi Group,

I'm living in Germany, so there is no access to the G1 right now. Also
as far as I know the G1 will come with a 2 year subscription from t-
mobile...

So my idea is to deploy the Android System on another handset. I have
a spare Samsung I600 (comparable with the Samsung BlackJack 1) lying
here. So it should be possible to install Android on it (removing the
existing windows mobile).

Am I right? Is there any possibility? What - exept building Android -
do I have to do? Which requirements do I have to keep an eye on?

Are there any hints, links etc for me?

MArtin

--~--~---------~--~----~------------~-------~--~----~

2. how the library files (c, c++) are linked with framework (java files)

Hi,

How is the framework and the corresponding library files are linked
through the JNI layer? Any particular example through with i can
understand one to one mappings from java to c/c++ code?

If anybody have worked on this, please reply.

Thanks in advance.

--~--~---------~--~----~------------~-------~--~----~

3. How to make a desktop widget?

4. Cannot compile Android app: "Failed to create debug key"

5. need some inputs/help

6. how to test if the screen is in HVGA-L mode

7. When is View ready?