The getLastKnownLocation() only returns in my experience valid locations if
there is elsewhere something that has subscribed to location updates, with
something like this:

public void subscribeToLocationUpdates() {
        this.lm =
(LocationManager)getSystemService(Context.LOCATION_SERVICE);
this.lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    }

The 'this' here is a class that also implements the LocationListener
interface.

I know this somehow does not make sense, but that is how I worked around
just getting nulls back.

HTH

Ludwig

2008/10/2 danielbr <[EMAIL PROTECTED]>

>
> Has anyone been successful in getting coordinates via the code below?
> I'm always getting null for the location, even after putting some fake
> coordinates via the DDMS controls.
>
> Daniel.
>
> On Sep 29, 12:55 pm, zl25drexel <[EMAIL PROTECTED]> wrote:
> > for those who are looking for solutions for this same question, here's
> > what I have, seems to work well with
> >
> > > > For telnet: telnet localhost 5554
> >
> > > > > geo fix <lat> <lon>
> >
> >       this.locationManager = (LocationManager)
> > getSystemService(Context.LOCATION_SERVICE);
> >      LocationmyLocation =
> > locationManager.getLastKnownLocation("gps");
> >       if(myLocation == null){
> >           Log.e("mylocation", "failed to determinemylocation");
> >       }else{
> >           Log.i("mylocation", myLocation.toString());
> >       }
> >
> > On Sep 29, 12:28 pm, zl25drexel <[EMAIL PROTECTED]> wrote:
> >
> > > Guillaume,
> >
> > > I understand that i need to mock the thecurrentlocationin the
> > > emulator, butmyquestion is what api calls do i make to get the lat/
> > > lon that i put in DDMS. I cannot find any documentations related to
> > > that in android's documentation.
> >
> > > On Sep 28, 4:53 am, Guillaume Perrot <[EMAIL PROTECTED]> wrote:
> >
> > > > And you have to manually simulate yourlocationusing telnet or DDMS
> > > > controls in Eclipse (the latter only works if your OS is in english
> > > > locale).
> > > > For telnet: telnet localhost 5554
> >
> > > > > geo fix 2 40
> >
> > > > On 28 sep, 04:05, Mark Murphy <[EMAIL PROTECTED]> wrote:
> >
> > > > >zl25drexelwrote:
> > > > > > Hi, sorry i am sure this had been asked before, how do i find
> outmy
> > > > > >currentlat/lon using thelocationAPI?
> >
> > > > > You can't, per se.
> >
> > > > > You can call getLastKnownLocation() to return, well, the last known
> > > > >location, but that may be null (if there have been no locations
> recorded
> > > > > for the requestedlocationprovider) or stale (if thelocationprovider
> > > > > has been out of service for a while).
> >
> > > > > Or, call requestLocationUpdates() and take action when you get new
> > > > > position fixes from thelocationprovider.
> >
> > > > > --
> > > > > Mark Murphy (a Commons Guy)http://commonsware.com
> > > > > _The Busy Coder's Guide to Android Development_ Version 1.2
> Published!
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to