在带有Google标记的应用程序中,我需要根据marker的检查设置checkbox的可见性。我已经在一个Java类中编写了Google Map Marker的代码,而该复选框在另一个Java类中。

我的代码是:

AgentTree.java

package com.extraslice.gmobile;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.SimpleAdapter;

import com.extraslice.gmobile.json.JsonImplementation;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class AgentTree extends AsyncTask<Void, Void, Void> {

    Context mContext;
    String mSeesionID;
    public static Marker agentmarker;
    AgentDetailsListener listener;
    public static SimpleAdapter sa;
    public static ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    MapImageClassification map_obj;

    public AgentTree(Context context, String sessionID,AgentDetailsListener cListner) {
        mContext = context;
        mSeesionID = sessionID;
        listener=cListner;
        map_obj = new MapImageClassification();
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Void doInBackground(Void... params) {
        try {


            //Log.i("SESSION ID AGENT", ""+mSeesionID);
            String stringRsp= JsonImplementation.jsonresp(GreaterActivity.main_url+"mandell-mvc/agent/giGetOrgGroupList/?sessionid="+GreaterActivity.temp_sessid);
            //get.setHeader("Accept", "application/json");

            Log.i("Response", ""+stringRsp);

            //Log.i("Response", ""+stringRsp);
            JSONObject rootObject = new JSONObject(stringRsp);
            String total = rootObject.getString("Total");
            //Log.i("TOTAL", ""+total);
            JSONArray Orgs = rootObject.getJSONArray("Orgs");
            //Log.i("my array", ""+Orgs);
            int l = Orgs.length();
            //Log.i("length", ""+l+"total"+total);
            for (int i = 0; i < l; i++) {
                final JSONObject temp1 = Orgs.getJSONObject(i);
                //Log.i("NMAE", ""+temp1);
                //final JSONArray jarrayTemp = temp1.getJSONArray("Groups");
                //final JSONObject temp2 = jarrayTemp.getJSONObject(0);
            //  final String MachGroupGuid = temp1.getString("MachGroupGuid");
                final String GroupName = temp1.getString("Name");
                //Log.i("NMAE", ""+GroupName);
              final String agent_ID = temp1.getString("ID");
                final String glatitude = temp1.getString("latitude");
                final String glongitude = temp1.getString("longitude");

                final String nonPriorityAgents = temp1
                        .getString("nonPriorityAgents");
                final String nonPriorityAgentsOffline = temp1
                        .getString("nonPriorityAgentsOffline");
                final String priorityAgentsInRecovery = temp1.getString("priorityAgentsInRecovery");
                final String priorityAgents = temp1.getString("priorityAgents");
                final String priorityAgentsOffline = temp1
                        .getString("priorityAgentsOffline");

                final String totalIncidents = temp1.getString("totalIncidents");
                final String grouptype = temp1.getString("OGType");

                final String agent_street = temp1.getString("streetLine");
                final String local_govt_agent = temp1.getString("localGovmt");
                final String agent_state = temp1.getString("usState");
                final String agent_country = temp1.getString("countryFK");
                final String agent_pin = temp1.getString("PostalCode");
                final String orgroot_Fk = temp1.getString("orgRootFK");


                HashMap<String, String> map = new HashMap<String, String>();
                map.put("Agent_Id", agent_ID);
                map.put("GroupName", GroupName);
                map.put("orgrootFk", orgroot_Fk);
                map.put("nonPriorityAgents", nonPriorityAgents);
                map.put("nonPriorityAgentsOffline", nonPriorityAgentsOffline);
                map.put("priorityAgents", priorityAgents);
                map.put("priorityAgentsOffline", priorityAgentsOffline);
                map.put("priorityAgentsInRecovery", priorityAgentsInRecovery);
                map.put("totalIncidents", totalIncidents);
                map.put("latitude", glatitude);
                map.put("longitude", glongitude);
                map.put("groupagents", grouptype);
                map.put("agent_street", agent_street);
                map.put("agent_localgovt", local_govt_agent);
                map.put("agent_state", agent_state);
                map.put("agent_country", agent_country);
                map.put("agent_pin", agent_pin);

                /*if (primaryPhone.equals(""))
                    primaryPhone= "No contact number listed";
                map.put("primaryPhone", primaryPhone);*/
                //map.put("other", priorityAgents+";"+priorityAgentsOffline+";"+nonPriorityAgents+";"+nonPriorityAgentsOffline+";"+totalIncidents);
                list.add(map);
            }
            Log.i("DO IN BACKGROUND", ""+list);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        Log.i("POSTEXECUTE", ""+list.size());
        if(list.size()>0)
        {
            /*Log.i("POSTEXECUTE", "");
            String [] from={"GroupName","nonPriorityAgents","nonPriorityAgentsOffline","priorityAgents","priorityAgentsOffline","totalIncidents"};
            int [] to={R.id.GroupName1,R.id.NonPriorityQty,R.id.NonPriorityOnline,R.id.PriorityQty,R.id.PriorityOnline,R.id.ticketsQty};
             sa=new SimpleAdapter(mContext, list, R.layout.agent_list, from, to);
            ListView agent_list=(ListView)((Activity)mContext).findViewById(R.id.agent_list);
            agent_list.setAdapter(sa);*/

            for(int i =0;i<AgentTree.list.size();i++)
        {
                double long_tude = 0;
                double lat_tude = 0;
                if((AgentTree.list.get(i).get("groupagents")).equals("GROUP"))
                {
                    //Log.i("LONGITUDE IN IF", "i"+2+(AgentTree.list.get(2).get("longitude")));
                    String s= (AgentTree.list.get(i)).get("longitude");
                    String s1= (AgentTree.list.get(i)).get("latitude");

                    String agentid=(AgentTree.list.get(i)).get("Agent_Id");
                    Log.i("long", ""+s);
                    int nonpriorityagents = Integer.parseInt((AgentTree.list.get(i)).get("nonPriorityAgents"));

                    int priorityAgents = Integer.parseInt((AgentTree.list.get(i)).get("priorityAgents"));
                    int NonpriorityAgents = Integer.parseInt((AgentTree.list.get(i)).get("nonPriorityAgents"));
                    int Nonpriorityoffline = Integer.parseInt((AgentTree.list.get(i)).get("nonPriorityAgentsOffline"));
                    int priorityAgentsOffline1=Integer.parseInt((AgentTree.list.get(i)).get("priorityAgentsOffline"));
                    int priorityAgentsInRecovery1 = Integer.parseInt((AgentTree.list.get(i)).get("priorityAgentsInRecovery"));
                    int total = nonpriorityagents+priorityAgents;

                    Log.i("Total", "AGENTTEE"+total);
                    Log.i("priorityagentsrecovery", "AGENTTREE"+priorityAgentsInRecovery1);
                    Log.i("priorityagentsoffline", "AGENTTREE"+priorityAgentsOffline1);
                    int map_icon=map_obj.getImage(total,priorityAgentsInRecovery1,priorityAgentsOffline1,priorityAgents,Nonpriorityoffline,NonpriorityAgents);

                    try
                    {
                        long_tude = Double.parseDouble(s);
                        lat_tude = Double.parseDouble(s1);
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }

                    *LatLng latLng = new LatLng(lat_tude,long_tude);
                agentmarker=    MainActivity.googleMap.addMarker(new MarkerOptions()
                    .position(latLng)
                    .title(""+agentid)
                    .snippet("agents")
                    .icon(BitmapDescriptorFactory.fromResource(map_icon))
                            );*
                    //map_icon=0;

                    /*if(MainActivity.org_chk.isChecked()==true){
                    agentmarker.setVisible(false);
                    }
                    else if(MainActivity.org_chk.isChecked()==false){
                        agentmarker.setVisible(true);
                    }*/
                    /** Add snippet() if necessary*********/
                }
            }

            listener.onComplete();
        }
        super.onPostExecute(result);
    }

    interface AgentDetailsListener
    {
        void onComplete();
    }

}


显示标记的代码是:

            LatLng latLng = new LatLng(lat_tude,long_tude);
        agentmarker=    MainActivity.googleMap.addMarker(new MarkerOptions()
            .position(latLng)
            .title(""+agentid)
            .snippet("agents")
            .icon(BitmapDescriptorFactory.fromResource(map_icon))
                    );


我需要在另一个类中设置此标记的可见性,我该如何完成?

最佳答案

尝试使用marker.setVisible(true)marker.setVisible(false)

08-18 07:52