Hello,

The code below gets the location information and displays it on
screen. If I use an emulator and provide such data manually, the
program works as expected. But I have Android device, but whenever I
run the program on the device the program displays 'Location not
found'. Now the program turns the GPS on, and I know there is no
problem with the way the GPS works because the Google Maps installed
in a device works.

What can I do to implement this important feature?

Cheers.

Karl.
____________________________________________________

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class WhereAmI extends Activity {
        @Override
        public void onCreate(Bundle icicle)
        {
                super.onCreate(icicle);
                setContentView(R.layout.main);
                LocationManager locationManager;
                String context = Context.LOCATION_SERVICE;
                locationManager = (LocationManager)getSystemService(context);
                String provider = LocationManager.GPS_PROVIDER;
                Location location = 
locationManager.getLastKnownLocation(provider);
                updateWithNewLocation(location);
        }

        private void updateWithNewLocation(Location location)
        {
                TextView myLocationText;
                myLocationText = (TextView)findViewById(R.id.myLocationText);
                if (location != null)
                {
                        double lat = location.getLatitude();
                        double lng = location.getLongitude();
                        myLocationText.setText("Your Current Position is \n 
Lat:" +lat+"\n
Long:"+lng );

                } else
                {
                        myLocationText.setText("Your Location Not Found");
                }
        }
}
--~--~---------~--~----~------------~-------~--~----~
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