gpt4 book ai didi

android - 如何在 android 中设置谷歌地图标记的可见性?

转载 作者:行者123 更新时间:2023-11-29 21:08:33 26 4
gpt4 key购买 nike

在带有谷歌标记的应用程序中,我需要根据checkbox 的检查来设置marker 的可见性。我在一个 java 类中编写了谷歌地图标记的代码,而复选框在另一个 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)

关于android - 如何在 android 中设置谷歌地图标记的可见性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23692706/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com