Store in a Bundle pass to your activity
public void onLocationChanged(Location loc) {
if (loc != null) {
double lat=loc.getLatitude();
double lon=loc.getLongitude();
Bundle bundle = new Bundle();
bundle.putDouble("lat", lat);
bundle.putDouble("lon", lon);
// Create Intent, store Bundle into Intent and paas intent to
another Activity
information = " "+lat +lon;
Toast.makeText(this, "Location Changed:"+information,
Toast.LENGTH_LONG).show();
}
}
And you can extract these value in OnCreate() of another Activity.
Bundle b = this.getIntent().getExtras();
- Anurag Singh
On Mon, Apr 19, 2010 at 10:24 AM, raqz <[email protected]> wrote:
> yes.. its getting the locations all right..but i am unable to save the
> location somwhere so that i can use it later. thats the whole
> issue....
>
> I just thought of something...
> if I start a service that does the onLocationChanged stuff....it would
> get the gps locations and store it (somewhere in the system)
> and later if i just start an acitivity that would do
> getLastKnowLocation() , shouldn't that fetch the location for further
> use.
> Come some one advise please
>
>
>
> On Apr 19, 12:22 am, Anurag Singh <[email protected]> wrote:
> > Have you set uses permission in manifiest file.
> >
> > <uses-permission
> > android:name="android.permission.ACCESS_FINE_LOCATION" />
> >
> > - Anurag Singh
> >
> > Hi,
> >
> >
> >
> >
> >
> > > I am trying to retrieve the GPS location of the phone. I believe I
> > > cannot create an object of the class which stores the location in a
> > > variable. So that once the class gets instantiated I use a get method
> > > and retrieve the content in the variable.
> > > So I am trying to do this....
> >
> > > locationListener = new MyLocationListener();
> >
> > > lm.requestLocationUpdates(
> > > LocationManager.GPS_PROVIDER,0,0,locationListener);
> > > if(!information.equals(null)){
> > > Bundle bundle = new Bundle();
> > > bundle.putString("hello", information);
> > > Intent intent = new Intent(LocationActivity.this,
> > > MainActivity.class);
> > > intent.putExtras(bundle);
> > > startActivity(intent);
> > > }
> >
> > > and in the locationlistener class
> >
> > > public void onLocationChanged(Location loc) {
> > > if (loc != null) {
> > > double lat=loc.getLatitude();
> > > double lon=loc.getLongitude();
> > > information = " "+lat +lon;
> > > Toast.makeText(getBaseContext(),
> > > "Location Changed:"+information,
> > > Toast.LENGTH_LONG).show();
> > > }
> > > else
> > > information="bad luck";
> > > }
> >
> > > The mainactivity then displays that...but its not happening...could
> > > some one please help me how to get the values of this.
> >
> > > Thanks...Raqeeb
> >
> > > --
> > > 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]<android-developers%[email protected]>
> <android-developers%[email protected]<android-developers%[email protected]>
> >
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
> >
> > --
> > 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]<android-developers%[email protected]>
> > For more options, visit this group athttp://
> groups.google.com/group/android-developers?hl=en
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
--
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