samedi 11 avril 2015

Marker with Profile Image

I want to show a marker with the image of a profile picture using the Picasso Library.


I can't determine how. The userProfilePicture is the URL of the profile picture of the user, and I am storing on userProfilePictureReceived.



public class GoogleMaps extends Activity implements OnMapReadyCallback {
protected GoogleMap map;
protected String userNameReceived;
protected String userProfilePictureReceived;
protected Bitmap bmp;
protected BitmapDescriptor icon;
protected Canvas canvas1;
protected ImageView icon2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_maps);
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

userNameReceived = MainActivity.userName;//using global variable userName from MainActivity class
userProfilePictureReceived = MainActivity.userProfilePicture;
// icon2 = (ImageView) findViewById(R.id.imageView2);
icon2.draw(canvas1);



Bitmap.Config conf = Bitmap.Config.ARGB_8888;
bmp = Bitmap.createBitmap(80, 80, conf);
canvas1 = new Canvas(bmp);

}


@Override
protected void onRestart() {
super.onRestart();
}

@Override
protected void onStart() {
Picasso.with(GoogleMaps.this)
.load(userProfilePictureReceived)
.resize(100, 100)
.config(Bitmap.Config.ARGB_4444)
// .error(R.drawable.abc_btn_radio_to_on_mtrl_015) // en caso de no tener imagen pone una predeterminada
.transform(new RoundedTransformation(50, 4))
.into(icon2);

icon2.draw(canvas1);
// BitmapDrawable drawable = (BitmapDrawable) icon2.getDrawable();
//userPictureAsGeoPoint = drawable.getBitmap();
//icon = BitmapDescriptorFactory.fromBitmap(userPictureAsGeoPoint);
super.onStart();
}

@Override
protected void onResume() {
super.onResume();
}

@Override
protected void onPause() {
super.onPause();
}

@Override
protected void onStop() {
super.onStop();
}

@Override
protected void onDestroy() {
super.onDestroy();
}

@Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title(userNameReceived))
.setIcon(BitmapDescriptorFactory.fromBitmap(bmp));


//marker.showInfoWindow
//marker.showInfoWindow
//setVisibility
}
}

Aucun commentaire:

Enregistrer un commentaire