如何在标记点击谷歌地图后从arraylist获取意图数据

时间:2014-04-17 08:52:31

标签: android google-maps android-intent arraylist marker

我使用数组列表来显示使用for循环的不同组织位置(标记)。

private void addMarkers() {
if (googleMap != null) {

    // getting intent data
    Intent in = getIntent();

    ArrayList<HashMap<String, String>> organizationList = (ArrayList<HashMap<String, String>>)in.getSerializableExtra("organization");

    for(int i = 0; i < organizationList.size(); i++) {
        name = organizationList.get(i).get(TAG_NAME);
        latitude = organizationList.get(i).get(TAG_LATITUDE);
        longitude = organizationList.get(i).get(TAG_LONGITUDE);

        lat = Double.parseDouble(latitude);
        longi = Double.parseDouble(longitude);

        googleMap.addMarker(new MarkerOptions().position(new LatLng(lat,longi)).title(name).visible(true));

    }

以下代码对点击标记

采取了措施
@Override
public boolean onMarkerClick(Marker marker) {
Log.i("GoogleMapActivity", "onMarkerClick");
Toast.makeText(getApplicationContext(),marker.getTitle(), Toast.LENGTH_LONG).show();
Intent in = new Intent(getApplicationContext(),SingleContactActivity.class);

in.putExtra(TAG_NAME, name);
in.putExtra(TAG_LATITUDE, latitude);
in.putExtra(TAG_LONGITUDE, longitude);
startActivity(in);
return false;}

我知道putExtra给出for循环的最后一个值的值.....请帮我发送另一个类点击的标记的确切值

2 个答案:

答案 0 :(得分:0)

试试这个。

@Override
    public void onInfoWindowClick(Marker arg0) {
        // TODO Auto-generated method stub

        Toast.makeText(getApplicationContext(),arg0.getTitle(), Toast.LENGTH_LONG).show();
        Intent in = new Intent(getApplicationContext(),SingleContactActivity.class);

        in.putExtra(TAG_NAME, name);
        in.putExtra(TAG_LATITUDE, latitude);
        in.putExtra(TAG_LONGITUDE, longitude);
        startActivity(in);

    }

答案 1 :(得分:0)

这是我解决的解决方案

  @Override
public boolean onMarkerClick(Marker marker) {
Log.i("GoogleMapActivity", "onMarkerClick");

Intent intent = getIntent();

@SuppressWarnings("unchecked")
ArrayList<HashMap<String, String>> organizationList = (ArrayList<HashMap<String, String>>)intent.getSerializableExtra("organization");

for(int i = 0; i < organizationList.size(); i++) {
    name = organizationList.get(i).get(TAG_NAME);

    if(marker.getTitle().equalsIgnoreCase(name)){

        latitude = organizationList.get(i).get(TAG_LATITUDE);
        longitude = organizationList.get(i).get(TAG_LONGITUDE);

        Intent in = new Intent(getApplicationContext(),SingleContactActivity.class);
        in.putExtra(TAG_NAME, name);
        in.putExtra(TAG_LATITUDE, latitude);
        in.putExtra(TAG_LONGITUDE, longitude);
        startActivity(in);

    }

}

return false;}