我正嘗試將我的地址通過intent.putExtra()
從其他活動傳遞給MapActivity
,並在MapActivity
之內完成了地理編碼。它沒有錯誤,但是當我運行時,它不顯示位置。任何人都可以告訴我我錯過了什麼或做錯了什麼?無法在Google地圖上顯示多個位置
僅供參考:我已將Listview Activity的地址傳遞給DisplayItem活動(它有效)。現在我想將它傳遞給MapActivity
貝婁是我的其他活動(ListViewActivity
)
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(ShoppingMall.this, Displayitem.class);
if (adapter.getItem(position).length > 0) {
intent.putExtra(Displayitem.EXTRA_ADDRESS, adapter.getItem(position)[4]);
intent.putExtra(MapsActivity.EXTRA_ADDRESS, adapter.getItem(position)[4]);
}
startActivity(intent);
}
});
我想把
intent.putExtra(MapsActivity.EXTRA_ADDRESS, adapter.getItem(position)[4]);
這個
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.myMap) {
Intent intent = new Intent(ShoppingMall.this,MapsActivity.class);
//Intent.putExtra
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
這是我的MapActivity
public static final String EXTRA_ADDRESS ="address";
private Bundle extras;
List<Address> location;
double lati, lon ;
.
.
.
.
private void getAddress(GoogleMap googleMap) {
try {
mMap = googleMap;
Intent intent = getIntent();
extras = intent.getExtras();
Geocoder geocoder = new Geocoder(this);
String address = extras.getString(this.EXTRA_ADDRESS);
location = geocoder.getFromLocationName(address, 1);
if (location.size() > 0) {
lati =location.get(0).getLatitude();
lon =location.get(0).getLongitude();
MarkerOptions options = new MarkerOptions()
.title("")
.position (new LatLng(lati, lon));
mMap.addMarker(options);
}
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
getAddress(googleMap);
setUpMap();
}
PS:新手在android系統
它在地圖上顯示。我可以製作單獨的課程嗎?像 Intent intent = new Intent(ShoppingMall.this,Mapactivity.class); and Intent intent = new Intent(ShoppingMall.this,Displayitem.class); – Critako
是的上面寫着MapActivity代碼和意圖傳遞displayitem。所以你可以創建兩個單獨的課程。 –
惠,我意識到這個問題,我已經更新了我的問題。希望你能理解 – Critako