Get Custom Title Marker Information Google Maps
Hi I´m working with google maps and I create a custom title on the markers that I have, I need to know when a marker is selected how do I get the info on the title, becouse I need
Solution 1:
try this:
Add your setOnInfoWindowClickListener
inside getInfoContents(Marker marker)
method:
map.setInfoWindowAdapter(newGoogleMap.InfoWindowAdapter() {
@Overridepublic View getInfoWindow(Marker marker) {
returnnull;
}
@Overridepublic View getInfoContents(Marker marker) {
Viewv= getLayoutInflater().inflate(R.layout.info_title, null);
finalTextViewinfo1= (TextView) v.findViewById(R.id.info1);
TextViewinfo2= (TextView) v.findViewById(R.id.info2);
TextViewinfo3= (TextView) v.findViewById(R.id.info3);
info1.setText("Fecha: " + u.getFecha());
info3.setText("Longitud: " + u.getLongitud().toString());
info2.setText("Ubicacion: "+obtenerDireccion(u.getLatitud(),u.getLongitud()));
map.setOnInfoWindowClickListener(newGoogleMap.OnInfoWindowClickListener() {
publicvoidonInfoWindowClick(Marker marker)
{
Fragment fragmento;
fragmento = newHistorialFragment();
Bundlebundle=newBundle();
bundle.putString("title",info1.getText().toString());
fragmento.setArguments(bundle);
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_principal, fragmento)
.commit();
}
});
return v;
}
});
Solution 2:
If you set the title of the Marker
doing
MarkerOptions punto= new MarkerOptions()
.position(ubicacion)
.title("Fecha: " + u.getFecha()); // set the marker titlemap.addMarker(punto);
You can retrieve it on the onInfoWindowClick
method doing:
map.setOnInfoWindowClickListener(newGoogleMap.OnInfoWindowClickListener() {
@OverridepublicvoidonInfoWindowClick(Marker marker) {
String title = marker.getTitle(); // Retrieve the title
}
});
Post a Comment for "Get Custom Title Marker Information Google Maps"