Good, I am developing an android app, in it I have an instance of google maps
where I draw several markers.
If I only paint one, the map shows me the tools where I can give it and that I open the map application with the route between my position and the marker that I have pressed, but when painting several markers this option is removed, I would like call that function from another fragment, passing the position to where I want it to generate the route. Is it possible to do this? How could he do it?
I load the map:
@Override
public void onMapReady(GoogleMap map) {
googleMap = map;
googleMap.setMapType(MAP_TYPE_NORMAL);
//googleMap.getUiSettings().setMapToolbarEnabled(false); //desactiva la opción de abrir google maps para ir al marcador
CameraPosition camPos = new CameraPosition.Builder()
.target(l) //Centramos el mapa en Madrid
.zoom(12) //Establecemos el zoom en 19
.bearing(0) //Establecemos la orientación con el noreste arriba
.tilt(70) //Bajamos el punto de vista de la cámara 70 grados
.build();
CameraUpdate camUpd3 = CameraUpdateFactory.newCameraPosition(camPos);
googleMap.addMarker(new MarkerOptions().position(
new LatLng(l.latitude, l.longitude))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))
);
for(int i=0;i<centros.size();i++){
googleMap.addMarker(new MarkerOptions().position(
new LatLng(centros.get(i).getLat(),centros.get(i).getLon())).title(centros.get(i).getNombre())
.snippet(centros.get(i).getDire()).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))
);
}
googleMap.animateCamera(camUpd3);
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Toast.makeText(getActivity(),
"id: "+marker.getId(),
Toast.LENGTH_LONG).show();
CentroAcciones fragmentCentro = new CentroAcciones();
getFragmentManager().beginTransaction().replace(R.id.container, fragmentCentro).commit();
return false;
}
});
}
Actions Center
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(centroacciones, container, false);
//TODO: obtiene null en las referencias a los botones
llamar=(Button) rootView.findViewById(R.id.llamar);
llamar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(getActivity(),"Boton llamar",Toast.LENGTH_LONG).show();
try {
//TODO: obtener el tlf del centro que recibe como parámetro
String phone="1234567890";
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:"+phone)); //String phone
startActivity(call);
} catch (Exception e) {
//Log.e("Excepción", e+"");
Toast.makeText(getActivity(),"No se encontró aplicación para llamar.",Toast.LENGTH_SHORT).show();
}
}
});
llegar=(Button) rootView.findViewById(R.id.llegar);
llegar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getActivity(),"Boton llegar",Toast.LENGTH_LONG).show();
}
});
solicitar=(Button) rootView.findViewById(R.id.solicitud);
solicitar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
centrosolicitar =new CentroSolicitar();
getFragmentManager().beginTransaction().replace(R.id.container, centrosolicitar).commit();
}
});
return rootView;
}
in this on create I have three options, call, route and request, call me launches the dialer with the phone, request me throw another fragment with their actions and my question is focused on route, since that is where I would like to launch google maps with the route from my position to the longitude-latitude of that center.
Thanks