Location is just a class representing a geographic location.

You need to do something like this:

    LocationManager lm = (LocationManager)getSystemService
(Context.LOCATION_SERVICE);
    List providers = lm.getAllProviders();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
locationListener);
    Location loc = lm.getLastKnownLocation
(LocationManager.GPS_PROVIDER);
    if (loc != null) {
        // loc.getLatitude()
        // loc.getLongitude()
    }

    private final LocationListener locationListener = new
LocationListener() {
        public void onLocationChanged(Location newloc) {}
        public void onProviderDisabled(String provider) {}
        public void onProviderEnabled(String provider) {}
        public void onStatusChanged(String provider, int status,
Bundle extras) {}
    };

Note: The getLastKnownLocation() method will return null until the
provider you specify has gotten at least one update.

--
Jack Ha
Open Source Development Center
・T・ ・ ・Mobile・ stick together

The views, opinions and statements in this email are those of
the author solely in their individual capacity, and do not
necessarily represent those of T-Mobile USA, Inc.


On Aug 10, 10:55 am, cellurl <[email protected]> wrote:
> Thanks for that. I just want one fix one time, not updates. I will try
> LM, but why can't I use vanilla Location like the API says?
> (My question is more of a learning one, if there is a more appropriate
> Class, why shouldn't I use it?)
> Everyone says GPS is a battery hog, so I just want to get a fix and
> turn it off as quickly as possible.
> -jp
>
> Location        A class representing a geographic location sensed at a
> particular time (a "fix").
> LocationManager         This class provides access to the system location
> services.
>
> On Aug 10, 12:25 am, Jack Ha <[email protected]> wrote:
>
> > You need to use the LocationManager:
>
> >     lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
>
> > --
> > Jack Ha
> > Open Source Development Center
> > ・T・ ・ ・Mobile・ stick together
>
> > The views, opinions and statements in this email are those of
> > the author solely in their individual capacity, and do not
> > necessarily represent those of T-Mobile USA, Inc.
>
> > On Aug 9, 9:22 pm, cellurl <[email protected]> wrote:
>
> > > From GPS, I am trying to get latitude longitude, bearing and speed.
> > > Just a one time snapshot.
>
> > > My code is 
> > > here:http://code.google.com/p/speedlimit/source/browse/#svn/trunk/Speedlim...
>
> > > Pblm:
> > > The "loc" is always 0.
>
> > > Q: Must I initialize the GPS provider somehow??
> > > Any complete code snippet most welcomed...
>
> > > -----excerpt from Speedlimit.java---
>
> > >          Gps gps = new Gps();
> > >          gps.doit();
>
> > > ------Gps.java--------------------------------
>
> > > package org.speedlimit;
>
> > > import android.app.Activity;
> > > import android.location.Location;
>
> > > public class Gps extends Activity
> > > {
> > >    private Location loc;
>
> > >     public void doit() {
>
> > >         if (loc != null) {
> > >                 double lat= loc.getLatitude();
> > >                 double lon= loc.getLongitude();
> > >         }
> > >     }}
>
> > > --------------------------------------
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to