Get Custom class data information on Map V2 PopupClick event in android
Asked Answered
I

1

0

hello friends my java file as below

public class MainActivity extends FragmentActivity {

GoogleMap googleMap;

final int RQS_GooglePlayServices = 1;
Double lat;
Double lng;
Marker marker;
LatLng coordinate;
private LocationManager locationManager;
private String provider;
Marker startPerc;
AutoCompleteTextView mAutoCompleteTextViewAddress;
CommonMethods mCommonMethods;
String getsearchingAddress;

Geocoder mGeocoder;
List<Address> list;
int maxResult = 10;
String addressList[];
Intent mIntent;

public double latitude;
public double longitude;
private HashMap<String, String> eventMarkerMap;

LatLng mLatLng;

public static double CurrentLatitude;
public static double CurrentLongitude;
DatabaseConnectionAPI mDatabaseConnectionAPI;
ArrayList<ParserRestaurant> mArrayListRestaurent;
ArrayList<ParserBranch> mArrayListBranch;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mCommonMethods = new CommonMethods();
    // initilizeMap();
    mDatabaseConnectionAPI = new DatabaseConnectionAPI(
            getApplicationContext());
    try {
        mDatabaseConnectionAPI.createDataBase();
        mDatabaseConnectionAPI.openDataBase();
    } catch (IOException e) {
        e.printStackTrace();
    }

    mArrayListBranch = new ArrayList<ParserBranch>();
    mArrayListBranch = mDatabaseConnectionAPI.getBranchData();


    if (googleMap == null) {
        googleMap = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();

        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        if (googleMap == null) {
            // Toast.makeText(getApplicationContext(),
            // "Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
        }
    }

    for (int i = 0; i < mArrayListBranch.size(); i++) {

        ParserBranch mBranch=new ParserBranch();
        mBranch.setBrId(mArrayListBranch.get(i).getBrId());
        LatLng coordinate = new LatLng(Double.parseDouble(mArrayListBranch
                .get(i).getBrLat()), Double.parseDouble(mArrayListBranch
                .get(i).getBrLng()));
        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(Double.parseDouble(mArrayListBranch.get(i)
                        .getBrLat()), Double.parseDouble(mArrayListBranch
                        .get(i).getBrLng())), 8.0f));
        Marker startPerc = googleMap
                .addMarker(new MarkerOptions()
                        .position(coordinate)
                        .title(mArrayListBranch.get(i).getResName())
                        .snippet(mArrayListBranch.get(i).getAddress())
                        .icon(BitmapDescriptorFactory
                                .defaultMarker(BitmapDescriptorFactory.HUE_YELLOW)));
        eventMarkerMap = new HashMap<String, String>();
        System.out.println("fd " + mArrayListBranch.get(i).getBrId());
        System.out.println("Marker ID "+startPerc.getId());
        eventMarkerMap.put(startPerc.getId(), mArrayListBranch.get(i).getBrId());
    }

    googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {

            String eventInfo = eventMarkerMap.get(marker);
            System.out.println("ID " + eventInfo);
            marker.hideInfoWindow();

        }
    });

    googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker marker) {

            return null;
        }

        // Defines the contents of the InfoWindow
        @Override
        public View getInfoContents(Marker marker) {

            // Getting view from the layout file info_window_layout

            View v = getLayoutInflater().inflate(R.layout.row_map, null);

            // Getting reference to the TextView to set title
            TextView note = (TextView) v.findViewById(R.id.txt_name);
            TextView snip = (TextView) v.findViewById(R.id.txt_snip);
            note.setText(marker.getTitle());
            snip.setText(marker.getSnippet());
            // Returning the view containing InfoWindow contents
            return v;

        }

    });


}

when i run above code multiple pin is drop onmap but i want to get particular marker information when i click on that marker so i take setOnInfoWindowClickListener for that and print value if particlur marker id but it gave me every time null any idea how can i solve it ?

Intellect answered 26/12, 2013 at 11:31 Comment(2)
what you need info of clicked point?or what?Kovar
@appubala: i want when i click on any popup button at that i wnat to get all data of that particular popup item whatevr i define inmy custom class like(br_id,br_name,br_detail, br_time, etc..)Intellect
K
0

You are putting marker id as a map key:

eventMarkerMap.put(startPerc.getId(), mArrayListBranch.get(i).getBrId());

but you are trying to retrieve your value using marker object:

String eventInfo = eventMarkerMap.get(marker);
Keeping answered 1/3, 2014 at 9:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.