Issue
I tried to add a drawable
in a marker google maps but it doesn't worked.
I followed many tutorials and tried many things without success...
Anyone can help me ?
this is my code :
I think the problem is ".icon(icon)"
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.ic_radar);
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney").icon(icon));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
Solution
You have to first change it to BitmapDrawable
then convert into Bitmap
, then only you can add image to a marker
, do it something like this:
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
BitmapDrawable bitmapdraw=(BitmapDrawable)getResources().getDrawable(R.drawable.icon);
Bitmap b=bitmapdraw.getBitmap();
Bitmap smallMarker = Bitmap.createScaledBitmap(b, 84, 84, false);
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney").icon(BitmapDescriptorFactory.fromBitmap(smallMarker)));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
I hope this will help.
Answered By - Ashish Gupta
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.