1

我收集了不同地理位置的經度和緯度。 我想知道如果我可以將它們設置爲例如字符串數組(字符串經緯度= {「9385853.0094」,「23123123.234」),然後通過意圖傳遞它們,以便我可以顯示谷歌地圖中的位置使用lat/long in新的活動。通過意向傳遞緯度/經度

+1

有關在活動之間傳遞數據的信息,請參閱http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android。當Google地圖活動加載時,請讀取傳遞的數據並設置座標。另外,您可以向我們展示您創建新活動或意向的代碼嗎? – WOUNDEDStevenJones 2015-02-17 22:31:36

回答

4

例如,您有兩個名爲Maps.java和Routes.java的類。

使用下面的代碼要通過經緯度

LatLng fromPosition = new LatLng(9385853.0094, 23123123.234); 
LatLng toPosition = new LatLng(11.145315551, 99.333455333); 

Bundle args = new Bundle(); 
args.putParcelable("from_position", fromPosition); 
args.putParcelable("to_position", toPosition); 

i.putExtra("bundle", args); 

Intent i= new Intent(Maps.this, Routes.class); 
     startActivity(i); 

,並在接收端使用下面的代碼

Bundle bundle = getIntent().getParcelableExtra("bundle"); 
LatLng fromPosition = bundle.getParcelable("from_position"); 
LatLng toPosition = bundle.getParcelable("to_position"); 

希望這有助於!