Mark,
Thanks for the reply. I need to serach harder for blog posts with
"working" code, I've
been reading posts that complain about problems :)
Here's what I do:
// Favor the network location source
String bestProvider = null;
if (locationManager.isProviderEnabled("network")){
bestProvider = "network";
}
else if (locationManager.isProviderEnabled("gps")){
bestProvider = "gps";
}
else{
bestProvider = null;
locationDisabled = true;
lastlocation = null;
return;
}
try{
myLocationListener = new LocationListener(){
public void onLocationChanged(Location location){
if (location != null){
lastlocation = location;
}
}
public void onProviderDisabled(String provider){
locationDisabled = true;
lastlocation = null;
if (locationManager != null && myLocationListener != null){
locationManager.removeUpdates(myLocationListener);
}
myLocationListener = null;
}
public void onStatusChanged(String provider, int status, Bundle
extras)
{
// 0 means the provider is out of service
if (0 == status){
locationDisabled = true;
lastlocation = null;
if (locationManager != null && myLocationListener != null){
locationManager.removeUpdates(myLocationListener);
}
myLocationListener = null;
}
else{
locationDisabled = false;
}
}
public void onProviderEnabled(String arg0) {
locationDisabled = false;
}
};
locationDisabled = false;
locationManager.requestLocationUpdates(bestProvider, 5000, 0,
myLocationListener);
}
catch(Exception e)
{
};
}
I call this code again whever the location provider "goes away."
Thanks for the suggestions about debugging. Will give it a go.
On Jun 2, 8:42 pm, Mark Murphy <[email protected]> wrote:
> pawpaw17 wrote:
> > In my activities onCreate method I start listening for location
> > updates as follows:
>
> > locationManager.requestLocationUpdates(bestProvider, 5000, 0,
> > myLocationListener);
>
> > Previously I used 60,000 ms instead of 5,000 ms.
>
> > The problem is that I have trouble getting the first update.
>
> > public void onLocationChanged(Location location){
> > if (location != null){
> > lastlocation = location;
> > }
> > }
>
> > onLocationChanged doesn't get called.
>
> > Now, if I switch to Maps and find the current location there, then
> > switch back to
> > my app, I finally get the onLocatinoChanged method to fire.
>
> > This whole location changed stuff seems rinky in Android. Is there a
> > way to
> > more directly insist that the Location hardware do it's thing?
>
> You assume the existence of location hardware. Not all devices will have
> location hardware (a.k.a., GPS).
>
> > Any help would be very much appreciated.
>
> 1. What location provider are you attempting to use?
>
> 2. Does LogCat tell you anything? You can examine this via adb logcat,
> DDMS, or the DDMS perspective in Eclipse.
>
> 3. Have you tried any location code that is known to work (e.g., from a
> blog post)?
>
> --
> Mark Murphy (a Commons
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android App Developer Training:http://commonsware.com/training.html- Hide
> quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---