user22707
user22707

Reputation: 505

Set a marker icon in Google Maps API

I am using Xamarin and am using the SimpleMapDemo and I have a question about setting a MarkerOptions object to have a different icon.

Here is my current code:

marker1.Icon(SetFeatureDrawable('Icon.png'));

This above code is not working.

May I please have some help to set the icon to be the icon that is in the Drawable folder that has the name of 'Icon.png'?

Thanks in advance

EDIT

Here is my code:

marker1.Icon(BitmapDescriptorFactory.FromResource(Resource.Drawable.monkey));

This is the error I am getting:

Non-invocable member 'Android.Gms.Maps.Model.MarkerOptions.Icon' cannot be used like a method

Here is my code to try and set the icon:

marker1.Icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.monkey);

This is the error I am getting:

CS0200: Property or indexer 'Android.Gms.Maps.Model.MarkerOptions.Icon' cannot be assigned to -- it is read only (CS0200)

Upvotes: 4

Views: 9098

Answers (3)

Saggy
Saggy

Reputation: 118

Try this one, using this i can show custom icon from drawable resource as marker in map

    MarkerOptions markerOptions = new MarkerOptions();

    // Setting position on the MarkerOptions
    markerOptions.SetPosition(lt);
    markerOptions.InvokeIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin));

custom map marker in google map

Upvotes: 2

Tom Opgenorth
Tom Opgenorth

Reputation: 1511

Try this code instead:

marker1.InvokeIcon(SetFeatureDrawable('Icon.png'));

In general, Xamarin tries to bind the Java setter/getters to properties. In this case, although MarkerOption.icon looks like a property to C# eyes, it is in fact a Java method. In this case the binding has "translated" the property-like Java method to MarkerOption.InvokeIcon in an attempt to conform with C# design guidelines.

Upvotes: 3

Satyaki Mukherjee
Satyaki Mukherjee

Reputation: 2879

Try in this way:

double latitude = 0.0;
double longitude = 0.0;

MarkerOptions mapMarker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Your title will be here");

mapMarker .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon)));

mapView.addMarker(mapMarker );

Upvotes: 2

Related Questions