guys i am just following a simple example here where i need to get my
location lat and longitude but its not working although its so simple i cant
find where i fall

but here is my code

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        LocationManager locationManager ;
        String context = Context.LOCATION_SERVICE;
        locationManager = (LocationManager)getSystemService(context);

        Criteria myCriteria = new Criteria();
        myCriteria.setAccuracy(Criteria.ACCURACY_FINE);
        myCriteria.setAltitudeRequired(false);
        myCriteria.setBearingRequired(false);
        myCriteria.setCostAllowed(true);
        myCriteria.setPowerRequirement(Criteria.POWER_LOW);

        String provider = locationManager.getBestProvider(myCriteria, true);

        Location myLocation =
locationManager.getLastKnownLocation(provider);

        if (myLocation != null)
        updateWithNewLocation(myLocation,provider);

        //locationManager.requestLocationUpdates(provider, 200000, 300,
locationListener);

        }

    private void updateWithNewLocation(Location myLocation,String provider)
{
        // TODO Auto-generated method stub
        String latLongString;
        TextView myLocationText;
        myLocationText = (TextView)findViewById(R.id.myLocationText);
        if (myLocation!=null)
        {

            double lat = myLocation.getLatitude();
            double lng = myLocation.getLongitude();
            latLongString = "Lat:" + lat + "\nLong" + lng + "\n" + provider
;

        }
        else {
            latLongString = "No Location Found" + provider ;
            }
        myLocationText.setText("My current position is :\n"+ latLongString);
        }



    private final LocationListener locationListener= new LocationListener(){
    public void onLocationChanged(Location location){
        updateWithNewLocation(location,"x");
           }

    public void onProviderDisabled(String provider){
        updateWithNewLocation(null,"x");
        }
    public void onProviderEnabled(String provider){}

    public void onStatusChanged(String provider,int status,Bundle extras){}



    };


}
-- 
Regards

Abdalrahman Eweiwi
Msc in Media Informatics
RWTH-AACHEN
B-it

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