LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000L,500.0f, this); Location loc = lm.getLastKnownLocation(lm.getProviders(true).get(0));
is what works for me On Sun, Oct 18, 2009 at 6:46 PM, pavan <xpress2pa...@gmail.com> wrote: > > package android_programmers_guide.AndroidLBS; > > import android.app.Activity; > import android.os.Bundle; > import android.location.LocationManager; > import android.view.View; > import android.widget.TextView; > import android.content.Context; > import android.widget.Button; > public class androidlbs extends Activity { > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle icicle) { > super.onCreate(icicle); > setContentView(R.layout.main); > final Button gpsButton = (Button) findViewById(R.id.gpsButton); > gpsButton.setOnClickListener(new Button.OnClickListener() { > public void onClick(View v){ > LoadCoords(); > }}); > } > public void LoadCoords(){ > TextView latText = (TextView) findViewById(R.id.latText); > TextView lngText = (TextView) findViewById(R.id.lngText); > LocationManager myManager = (LocationManager) > getSystemService(Context.LOCATION_SERVICE); > Location latt = myManager.getCurrentLocation("gps"); //error is here > Double latPoint = latt.getLatitude(); > Double lngPoint = latt.getLongitude(); > latText.setText(latPoint.toString()); > lngText.setText(lngPoint.toString()); > } > } > > I using the above code to find my location on mobile. But the lines > > Location latt = myManager.getCurrentLocation("gps"); > > throwing error in eclipse saying getCurrentLocation is not associated > with locationmanager. Can anyone help me in this regard. > > Thanks > Pavan > > > > -- Writing code is one of few things that teaches me I don't know everything. http://www.fuligin.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---