[英]passing GPS coordinates to activity
我正在嘗試將經度和緯度變量傳遞給Google地圖片段的另一個活動。 到目前為止,我已經做到了
Intent i = new Intent(Main.this, Main2.class);
i.putExtra(Double.toString(gettextLong), xLocation.getLongitude());
i.putExtra(Double.toString(gettextLat), xLocation.getLatitude());'
我如何在其他活動中收到它?
嘗試:
Intent i = new Intent(Main.this, Main2.class);
i.putExtra("lon", xLocation.getLongitude());
i.putExtra("lat", xLocation.getLatitude());
像這樣:
int lat = getIntent().getExtras().getDouble("lat");
int lon = getIntent().getExtras().getDouble("lon");
提供相關的密鑰,例如
Intent i = new Intent(Main.this, Main2.class);
i.putExtra("longitude", xLocation.getLongitude());
i.putExtra("latitude", xLocation.getLatitude());
和在Main2活動中
Bundle extras = getIntent().getExtras();
if(extras !=null && extras.getDouble("latitude") != null && extras.getDouble("longitude") != null) {
double lat = extras.getDouble("latitude");
double lng = extras.getDouble("longitude");
}
在第二個活動中使用getIntent()和getDoubleExtra() 。 但是以不同的方式傳遞它。 putExtra中的第一個參數應該是一些String,但是您必須了解他,以后在第二個活動中需要使用它。 喜歡:
public static final String FIRST = "firstArgument";
i.putExtra(FIRST, xLocation.getLongitude());
在Main2中:
double i = getIntent().getDoubleExtra(Main.FIRST, 0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.