2011-06-10 60 views
0

朋友我做了一個基於位置的應用程序。通過全球定位系統的長期和緯度到其他活動

我已經實現了所有的代碼,當我的位置被改變時,它調用LocationListener接口的onLocationChanged方法。

我也使用onUpdateLocation()方法來獲取位置更新,現在我想通過拉特和長期的活動。我怎樣才能做到這一點 ??

修訂

我知道使用意向。但我應該在哪裏調用意圖?

我不能把它onLocationChanged Mthod/

請指導

回答

1

另一種解決方案是創建活動的內廣播接收器。每當位置更新時,LocationListener就會廣播消息。在這個消息裏面你可以放置經度和緯度值。

使用這種方式,您可以動態更新值。

0

我使用意向。

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

然後使用

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

在YourDestinationActivity

0

使用廣播是更好的方式,因爲位置信息和活動需要鬆散耦合,並傳遞這樣的數據異步更安全。