无法在Google地图上显示多个位置

时间:2016-04-26 06:27:36

标签: android google-maps android-activity

我正试图通过intent.putExtra()从其他活动将我的地址传递给MapActivity,并在MapActivity内部完成了地理编码。它没有错误,但是当我运行时,它没有显示位置。谁能告诉我我错过了什么或做错了什么?

仅供参考:我已经将Listview Activity中的地址传递给DisplayItem活动(它可以工作)。现在我想将它传递给MapActivity

Bellow是我的另一项活动(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中的新手

2 个答案:

答案 0 :(得分:0)

试试这个......

Intent intent = new Intent(ShoppingMall.this, Mapactivity.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);

答案 1 :(得分:0)

<property name="cache.use_query_cache">true</property> <property name="cache.use_second_level_cache">true</property> 
            <property name="cache.use_structured_entries">true</property> <property name="cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property> 
            <property name="net.sf.ehcache.configurationResourceName">ehcache.xml</property>