4

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)
user22707
  • 505
  • 1
  • 13
  • 23

3 Answers3

3

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.

Tom Opgenorth
  • 1,511
  • 1
  • 12
  • 19
2

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 );
Satyaki Mukherjee
  • 2,857
  • 1
  • 22
  • 26
2

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

Saggy
  • 118
  • 1
  • 6