that is how to retrieve your location from the gps. But your code
requires another activity (such as the build-in google map app) to
listen for gps updates first.
To listen for gps update pro actively, try

    private final LocationListener onLocationChange = new
LocationListener() {
        public void onLocationChanged(Location location) {
            if(location != null){
                lastLocation = location;
            }
        }

        public void onProviderDisabled(String provider) {
            // required for interface, not used
        }

        public void onProviderEnabled(String provider) {
            // required for interface, not used
        }

        public void onStatusChanged(String provider, int status,
Bundle extras) {
            // required for interface, not used
        }
    };

    @Override
    public void onResume() {
        super.onResume();
 
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
1000L /*1 sec between update*/,
                500.0f/*receive update if greater than 500m change*/ ,
onLocationChange);
 
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
1000L /*1 sec between update*/,
                500.0f/*receive update if greater than 500m change*/ ,
onLocationChange);
    }

On Oct 28, 10:51 pm, disappearedng <[EMAIL PROTECTED]> wrote:
> Hi everyone
> Please look at my method which involves retrieving a GPS location
> using myManager.getLastKnownLocation("gps").
> I am pretty sure that's not how it works.
>
> Can someone please help me?
>
> public void LoadCoords()        {
>         TextView latText = (TextView) findViewById(R.id.latText);
>         TextView longText = (TextView) findViewById(R.id.longText);
>         LocationManager myManager = (LocationManager)
> getSystemService(Context.LOCATION_SERVICE);
>
>         /*
>         GeoPoint p = new GeoPoint((int) (47.47 * 1E6),(int) (-122.01 *
> 1E6));
>
>         Double latPoint = (double) p.getLatitudeE6();
>         Double longPoint = (double) p.getLongitudeE6();
>
>         */
>         Double latPoint =
> myManager.getLastKnownLocation("gps").getLatitude();
>         Double longPoint =
> myManager.getLastKnownLocation("gps").getLatitude();
>
>         latText.setText(latPoint.toString());
>         longText.setText(longPoint.toString());
>
>     }
--~--~---------~--~----~------------~-------~--~----~
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