I'm trying to pass the value from the marker to the setOnInfoWindowClickListener, but I'm not sure what the best way for this is, can anyone help me? It even passes a value, but not the loop, that is, it is not passing the value of the marker by id. my code.
Full Code
private class MapaGet extends AsyncTask<String, Void, Void> implements GoogleMap.OnInfoWindowClickListener {
// Lista onde vamos guardar os valores
List<MapasController> ListaDeController = new ArrayList<MapasController>(0);
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(ViewMaps.this);
pDialog.setMessage("Por favor, aguarde...");
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected Void doInBackground(String... arg0) {
// Creating service handler class instance
cx = new Conexao();
String jsonStr = cx.get(url);
Log.d("Resposta: ", "> " + jsonStr);
if (jsonStr != null) {
try {
// De-serialize the JSON
JSONArray jsonArray = new JSONArray(jsonStr);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObj = jsonArray.getJSONObject(i);
MapasController mc = new MapasController();
mc.setLatitude(jsonObj.getDouble(TAG_LATITUDE));
mc.setLongitude(jsonObj.getDouble(TAG_LONGITUDE));
mc.setTitulo(jsonObj.getString(TAG_TITULO));
mc.setDescricao(jsonObj.getString(TAG_DESCRICAO));
mc.setId(jsonObj.getString(TAG_ID));
mc.setStatus(jsonObj.getString(TAG_STATUS));
mc.setData(jsonObj.getString(TAG_DATA));
mc.setUsuario(jsonObj.getString(TAG_USUARIO));
mc.setCategoria(jsonObj.getString(TAG_CATEGORIA));
// Adicionamos na lista
ListaDeController.add(mc);
Log.d ("", "get " + mc.getCategoria() + "Longitude " + mc.getLatitude() + " " + jsonObj.getString(TAG_TITULO) );
}
} catch (JSONException e) {
Log.e("tag", "Error processing JSON", e);
}
} else {
Log.e("Get: ", "Não foi possível obter quaisquer dados do url");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Se o tamanho da lista fo maior que zero!
if(ListaDeController.size() > 0){
for(final MapasController mc : ListaDeController){
LatLng local = new LatLng(mc.getLatitude(), mc.getLongitude());
// Seleciona o ícone de acordo com a categoria do mesmo
Marker mapa = mMap.addMarker(new MarkerOptions()
.position(local)
.title(mc.getTitulo())
.snippet(mc.getDescricao())
.draggable(true)
.icon(BitmapDescriptorFactory.fromResource(icone))
);
mMap.getCameraPosition();
mMap.moveCamera(CameraUpdateFactory.newLatLng(local));
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.animateCamera(CameraUpdateFactory.zoomTo(19), 2000, null); // animação zoom 10 com 2 segundos
}
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent in = new Intent(ViewMaps.this, DescricaoMaps.class);
in.putExtra(TAG_ID, mc.getId());
in.putExtra(TAG_TITULO, mc.getTitulo());
in.putExtra(TAG_DESCRICAO, mc.getDescricao());
in.putExtra(TAG_DATA, mc.getData());
in.putExtra(TAG_STATUS, mc.getStatus());
in.putExtra(TAG_USUARIO, mc.getUsuario());
in.putExtra(TAG_CATEGORIA, mc.getCategoria());
ViewMaps.this.startActivity(in);
}
});
}
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// se o mapa não está nulo , vamos carregar
if (mMap != null) {
new MapaGet().execute();
}
}