Along with the title and snippet, how do I add extra data to the marker?

Problem: my remote server returns 10 values ​​for the request. I analyzed my answer and used the added markers for the loop (here I added information to the header and fragment) on the map (here I want to add additional data to the marker so that I can access it in the event event of the info window)

in infoWindowClickListener I want to access this additional data.

How to add additional data to a marker / how to access ph-data for a specific click of a marker (otherwise I get the last ph value in all markers).

I tried like this.

   private class HttpGetTask extends AsyncTask<Void, Void, String> 
    {
    //URL and http stuff
    }

            @Override
            protected void onPostExecute(String result) {

                try {
                     json = new JSONArray(result);

                    for (int i = 0; i < json.length(); i++) {
                        Log.v("Response", result);
                        final JSONObject e = json.getJSONObject(i);
                        String point = e.getString("point");

                        Log.v("POINT", point);//Checking points

                        String phone1 = e.getString("ph");
                        Log.v("PH", phone1);//Checking phone numbers

                        String[] point2 = point.split(",");//Splitting points
                        double lat1 = Double.parseDouble(point2[0]);
                        double lng1 = Double.parseDouble(point2[1]);
                        Log.v("LLDN", "" + lat1 + "&" + lng1);

                        //Adding multiple markers
//can i add extra information here along with title and snippet
                        gMap.addMarker(new MarkerOptions()
                                .title(e.getString("name"))
                                .snippet(
                                        e.getString("LS")+""+e.getString("ph") )
                                .position(new LatLng(lng1, lat1))
                                .icon(BitmapDescriptorFactory
                                        .fromResource(R.drawable.pmr)));

                    }
                } catch (JSONException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

Is it possible to add an additional value to the marker along with the title and fragment.? or am I misunderstood.?

+4
1

, , .

markersMap /.

private Map<Marker, ExtraDataObj> markersMap = new HashMap<Marker, ExtraDataObj>();

, .

ExtraDataObj extraDataObj = new ExtraDataObj();
// extract and store all data you want in the extraDataObj
....
...
..
Marker marker = gMap.addMarker(new MarkerOptions()
                        .title(e.getString("name"))
                        .snippet(
                                e.getString("LS")+""+e.getString("ph") )
                        .position(new LatLng(lng1, lat1))
                        .icon(BitmapDescriptorFactory
                                .fromResource(R.drawable.pmr)));
markersMap.put(marker, extraDataObj);

onInfoWindowClick markersMap

ExtraDataObj extraDataObj = markersMap.get(arg0) 
+2

Source: https://habr.com/ru/post/1537640/


All Articles