Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms Maps - Custom Pin Images

Is there a way to change the image of the pins in Xamarin Forms Maps. I want to make the pin a custom image, if it has to be done natively, can someone give me a simple example of it. Thank you.

like image 458
user3841879 Avatar asked Aug 18 '14 17:08

user3841879


3 Answers

To anyone coming to the later, this is now well supported in Xamarin Forms.

In essence you need to create a custom map class in your PCL or shared code that inherits from the Xamarin Forms Map and then create a Custom Renderer in each of the platforms' projects.

Those custom renderers will be different for each platform, dealing with the specifics of rendering icons and any pop up information shown when you click on that pin for that particular platform. You are not obliged to create a custom renderer for all platforms, for any that you don't a normal map will be displayed.

This is all now really well documented in the Custom Renderers | Customizing a Map section of the Xamarin Forms Developers Guide. That documentation walks through creating a custom renderer for Android, iOS and UWP and explains the code needed in detail. There's a lot of it, so I won't reproduce it here. There is also an accompanying sample solution here.

One point worth noting is that if you are trying to reproduce that code in your own project you will also need to add the images in the various drawable folders in the ProjectName\Droid\Resources directory, and also the two axml files in the layout directory.

like image 182
tomRedox Avatar answered Oct 19 '22 21:10

tomRedox


Apparently this is quite locked down and you have to look at custom renderers to achieve what you are needing.

There is a discussion about this on the following link:-

http://forums.xamarin.com/discussion/17916/customization-of-xamarin-forms-maps-pins

, with specific reference to a project at the following link which someone has implemented custom image pins from the Assets folder:-

https://github.com/paulpatarinski/ShouldIWashMyCar/blob/master/Android/Renderers/MapViewRenderer.cs

I haven't tried this yet, however this would probably be a good place to start when looking to customize map rendering.

like image 38
Pete Avatar answered Oct 19 '22 20:10

Pete


This project might be helpful to you. raechten/BindableMapTest

From the description:

Small sample for binding a collection to a Xamarin Forms Maps pins (valid until binding directly to the Pins property will be supported by Xamarin Forms directly).

Includes custom and clickable pins.

It has Android and iOS implementations.

like image 25
Timothy Lee Russell Avatar answered Oct 19 '22 21:10

Timothy Lee Russell