Cómo obtener el evento de clic del texto del marcador
Estoy mostrando google map api v2 en mi aplicación. He establecido algunos marcadores en el mapa. También he establecido el título y el fragmento en los marcadores que se muestran al hacer clic en el marcador.
Ahora quiero llamar a una nueva actividad cuando se hace clic en el título del marcador y no en el marcador en sí.
- Cómo mover un mapa bajo un marcador
- La API de Google Maps para Android v2 lanza GooglePlayServicesNotAvailableException, fuera de fecha, SupportMapFragment.getMap () devuelve null
- Geocode no funciona - Genymotion
- GoogleMaps GroundOverlay parpadea mis imágenes
- Google Maps y las aplicaciones con mapview tienen diferentes posiciones actuales
map.setOnMarkerClickListner
Se llama sólo en el clic del marcador.
Pero no quiero hacer eso. Quiero que el marcador para mostrar el título y el fragmento en el clic del marcador, pero quiero llamar a la nueva actividad en el clic del título.
¿Alguna idea de cómo lo hacemos?
Gracias
- ¿Cómo mostrar el popup en la superposición de tapping en android?
- NullPointer Exception en Android Google Maps durante la actualización de Mapa
- Android: Si los marcadores se superponen entre sí en el mapa, el evento de clic se disparará para el último escondido
- Utilizando OnTap (int i) con varias capas de ItemizedOverlay
- Android: abre la aplicación de navegación de Google desde Intent
- ¿Subir el mapa interior de Google? & ¿Cómo puedo comprobarlo y verlo?
- Siga la ubicación del usuario en React Native AirBnb MapView
- Google Maps Android API v2 - detectar el toque en el mapa
Para lograr esto debes implementar setOnInfoWindowClickListener
en tu método getInfoContents
para que un clic en tu ventana de infoContents
despierte al oyente para hacer lo que quieras, lo haces así:
map.setInfoWindowAdapter(new InfoWindowAdapter() { // Use default InfoWindow frame @Override public View getInfoWindow(Marker args) { return null; } // Defines the contents of the InfoWindow @Override public View getInfoContents(Marker args) { // Getting view from the layout file info_window_layout View v = getLayoutInflater().inflate(R.layout.info_window_layout, null); // Getting the position from the marker clickMarkerLatLng = args.getPosition(); TextView title = (TextView) v.findViewById(R.id.tvTitle); title.setText(args.getTitle()); map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { public void onInfoWindowClick(Marker marker) { if (SGTasksListAppObj.getInstance().currentUserLocation!=null) { if (String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) && String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLongitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8))) { Toast.makeText(getApplicationContext(), "This your current location, navigation is not needed.", Toast.LENGTH_SHORT).show(); } else { FlurryAgent.onEvent("Start navigation window was clicked from daily map"); tasksRepository = SGTasksListAppObj.getInstance().tasksRepository.getTasksRepository(); for (Task tmptask : tasksRepository) { String tempTaskLat = String.valueOf(tmptask.getLatitude()); String tempTaskLng = String.valueOf(tmptask.getLongtitude()); Log.d(TAG, String.valueOf(tmptask.getLatitude())+","+String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)); if (tempTaskLat.contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) && tempTaskLng.contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8))) { task = tmptask; break; } } Intent intent = new Intent(getApplicationContext() ,RoadDirectionsActivity.class); intent.putExtra(TasksListActivity.KEY_ID, task.getId()); startActivity(intent); } } else { Toast.makeText(getApplicationContext(), "Your current location could not be found,\nNavigation is not possible.", Toast.LENGTH_SHORT).show(); } } }); // Returning the view containing InfoWindow contents return v; } });
Para establecer un título en un marcador:
marker.showInfoWindow();
Para establecer un oyente de clics en el título:
googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker arg0) { // TODO Auto-generated method stub } });
GoogleMap mGoogleMap; mGoogleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker arg0) { Intent intent = new Intent(getBaseContext(), Activity.class); String reference = mMarkerPlaceLink.get(arg0.getId()); intent.putExtra("reference", reference); // Starting the Activity startActivity(intent); Log.d("mGoogleMap1", "Activity_Calling"); } });
/** * adding individual markers, displaying text on on marker click on a * bubble, action of on marker bubble click */ private final void addLocationsToMap() { int i = 0; for (Stores store : storeList) { LatLng l = new LatLng(store.getLatitude(), store.getLongtitude()); MarkerOptions marker = new MarkerOptions() .position(l) .title(store.getStoreName()) .snippet("" + i) .icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_GREEN)); googleMap.addMarker(marker); ++i; } googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker marker) { try { popUpWindow.setVisibility(View.VISIBLE); Stores store = storeList.get(Integer.parseInt(marker .getSnippet())); // set details email.setText(store.getEmail()); phoneNo.setText(store.getPhone()); address.setText(store.getAddress()); // setting test value to phone number tempString = store.getPhone(); SpannableString spanString = new SpannableString(tempString); spanString.setSpan(new UnderlineSpan(), 0, spanString.length(), 0); phoneNo.setText(spanString); // setting test value to email tempStringemail = store.getEmail(); SpannableString spanString1 = new SpannableString(tempStringemail); spanString1.setSpan(new UnderlineSpan(), 0, spanString1.length(), 0); email.setText(spanString1); storeLat = store.getLatitude(); storelng = store.getLongtitude(); } catch (ArrayIndexOutOfBoundsException e) { Log.e("ArrayIndexOutOfBoundsException", " Occured"); } } }); }
- Compruebe la conexión de red android
- Maven android plugin: No se puede encontrar una ruta de acceso a Android SDK