Shah
Shah

Reputation: 5020

Pass the long and lat by GPS to other activity

Friends i have made a location based application.

i have implemented all the code and when my location is changed it calls onLocationChanged method of LocationListener Interface.

I have also used onUpdateLocation() method to get location updates and now i want to pass the lat and long to the activity. How can i do that ??

UPDATED

I know to use Intent . But where should i call the Intent?

I can not call it in onLocationChanged Mthod/

Please Guide

Upvotes: 0

Views: 322

Answers (3)

Yilmaz Guleryuz
Yilmaz Guleryuz

Reputation: 9745

Using Broadcast is much better way, because location info and activities needs to be loosely coupled and passing such data async is safer.

Upvotes: 0

Plamen Nikolov
Plamen Nikolov

Reputation: 4187

Another solution is to create broadcast receiver inside of the activity. The LocationListener broadcasts a message each time a location is updated. Inside of this message you can put lat and lon values.

Using this way you can update the values dynamically.

Upvotes: 1

nahwarang
nahwarang

Reputation: 653

I use the Intent.

Intent intent = new Intent().setClass(YourActivity.this, YourDestinationActivity.class);
intent.putDoubleExtra("com.example.lat", yourLatValue);
intent.putDoubleExtra("com.example.long", yourLongValue);
startActivity(intent);

Then use

Double d = getIntent().getDoubleExtra("com.example.lat", -1); 

in YourDestinationActivity

Upvotes: 0

Related Questions