Darshan Khatri
Darshan Khatri

Reputation: 327

How to fix custom size of Google Maps marker in Android

How do I set the marker size. Can anyone tell me?

See This Image

Upvotes: 6

Views: 7705

Answers (4)

Alex
Alex

Reputation: 99

use Marker this way

<Marker
      anchor={{ x: 0.5, y: 1}}
      coordinate={location} 
>
      <Image style={styles.marker} source={image} />
    </Marker>

Upvotes: 1

Tom Howard
Tom Howard

Reputation: 4908

I assume you have a bmp image since you are setting a custom marker. To resize the bmp, use Bitmap.createScaledBitmap (Bitmap src, int width, int height, boolean filter)

Upvotes: 1

Fahim Al Mahmud Ashik
Fahim Al Mahmud Ashik

Reputation: 1121

It's happening because the icon you are using as a marker is bigger in size.So,You can first convert it into Bitmap and change its size and then use that bitmap in as a custom marker. For example I have made a method which resizes your bitmap and returns the resized bitmap.

public Bitmap resizeBitmap(String drawableName,int width, int height){
    Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(),getResources().getIdentifier(drawableName, "drawable", getPackageName()));
    return Bitmap.createScaledBitmap(imageBitmap, width, height, false);
}

Then call this method in googleMap.addMarker()

googleMap.addMarker(new MarkerOptions()
            .title("New Marker").position(yourGivenPosition).icon(BitmapDescriptorFactory.fromBitmap(resizeBitmap("your drawable name",72,64))));

Upvotes: 7

Yessine Mahdouani
Yessine Mahdouani

Reputation: 1264

Change the dimensions of your Marker image (icon), 30 x 40 it's ok I think

Upvotes: 1

Related Questions