Visualización de una imagen descargada de Internet como anotación – Uso de Picasso
No puedo mostrar la imagen descargada de Internet como anotación. Estoy implementando el siguiente código y la biblioteca de Picasso. Sin embargo, si utilizo una imagen local, funciona. Gracias de antemano por cualquier ayuda.
private void createAnnotation(int id, double lat, double lon, String caption, String photoUrl) { SKAnnotation annotation = new SKAnnotation(id); SKCoordinate coordinate = new SKCoordinate(lat, lon); annotation.setLocation(coordinate); annotation.setMininumZoomLevel(5); SKAnnotationView annotationView = new SKAnnotationView(); View customView = (LinearLayout) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate( R.layout.annotation_photo_and_text, null, false); // If width and height of the view are not power of 2 the actual size of the image will be the next power of 2 of max(width,height). //annotationView.setView(findViewById(R.id.customView)); TextView tvCaption = (TextView) customView.findViewById(R.id.annotation_photo_caption); tvCaption.setText(caption); ImageView ivPhoto = (ImageView) customView.findViewById(R.id.annotation_photo); Picasso.with(getApplicationContext()) .load(photoUrl) .resize(96, 96) //.centerCrop() .into(ivPhoto); //ivPhoto.setImageResource(R.drawable.hurricanerain); annotationView.setView(customView); annotation.setAnnotationView(annotationView); mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_NONE); }
- Android: cómo ampliar una plaza específica en los mapas de Skobbler
- Error al mostrar Mapa después de actualizar a Skobbler 2.2.0
- Habilitación del modo "navegación" en skobbler android API
- La vista de la cola de Skobbler se muestra incorrectamente Android SDK 2.5.1
- Cómo añadir un mapa de Skobbler a mi aplicación vacía
- ¿Por qué no se muestran las anotaciones personalizadas?
- Cómo utilizar createRouteFromTrackElement () en Skmap
- Cómo mostrar una ruta personalizada en SKmap
- ¿Qué proceso se debe utilizar para comprimir el archivo SKMaps.zip para usarlo en la aplicación Skobbler?
- Android Skobbler Maps 2.4 SDK - Mapas sin conexión / Prebundled Crashing
- SKMaps muestra fondo negro / azulado
- Cómo modificar una anotación de Skobbler sin agregarla de nuevo
- Mapas fuera de línea SDK para Android e iOS
Picasso carga imágenes de Internet asincrónicamente. Intente agregar la imagen a la Anotación después de haberla descargado. Puede utilizar un objetivo para escuchar la finalización de descarga de imágenes:
ImageView ivPhoto = (ImageView) customView.findViewById(R.id.annotation_photo); Target target = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { ivPhoto.setImageBitmap(bitmap); annotationView.setView(customView); annotation.setAnnotationView(annotationView); mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_NONE); } @Override public void onBitmapFailed(Drawable errorDrawable) {} @Override public void onPrepareLoad(Drawable placeHolderDrawable) {} }; ivPhoto.setTag(target); Picasso.with(getApplicationContext()) .load(photoUrl) .resize(96, 96) .into(target);
Pruebe el contexto de la actividad en lugar de applicationcontext. Puede funcionar para usted.
¿Qué pasa si intenta cargar la imagen utilizando el objeto de Target
y, a continuación, establecer bitmap descargado a su ImageView
?
Target target = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { // loading of the bitmap was a success // TODO do some action with the bitmap ivPhoto.setImageBitmap(bitmap); } @Override public void onBitmapFailed(Drawable errorDrawable) { // loading of the bitmap failed // TODO do some action/warning/error message } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }; ivPhoto.setTag(target); Picasso.with(getApplicationContext()) .load(photoUrl) .resize(96, 96) .into(target);