Add marker on map with label in Xamarin Android - visual-studio

I'm creating a Xamarin Android App in Visual Studio.
I've added a Google map v2 to my app, and also added markers. On tap of these markers, I've opened an info window.
Now, I want to customize these markers, so that markers are displayed with label on the top of it, like below:
Please suggest with code, for how to do this in Xamarin. I'm new to this environment.

You can use android-maps-utils as binding-library.
Sample app is here - oystehei/MapsUtilityDemo: Demo project for Google Maps Utility bindings project in Xamarin.
How to add a "text on marker" is described as follows.
var iconGen = new IconGenerator(activity);
var markerOp = new MarkerOptions().SetPosition(latLng);
iconGen.SetStyle(IconGenerator.StyleOrange);
markerOp.SetIcon(BitmapDescriptorFactory.FromBitmap(
iconGen.MakeIcon("text_on_marker")));
gogleMap.AddMarker(markerOp);

Related

How to add trivial OpenGL functionality to Xamarin forms app

Can anyone please help with the following?
I have a trivial Xamarin forms app working and I want to add an OpenTK view.
The following works fine:
In my MainPage.xaml.cs I have the following event handler for a button which spawns an empty OpenTK view on each click:
private void OnXAMLButtonClicked(object sender, EventArgs e)
{
var view = new OpenGLView { HasRenderLoop = true };
view.HeightRequest = 300;
view.WidthRequest = 300;
view.OnDisplay = r =>
{
//GL.ClearColor(red, green, blue, 1.0f);
};
m_SL.Children.Add(view);
}
(where m_SL is the name of my StackLayout).
I get a new black window on each click. Great.
Now, see that commented-out line, that's because the value GL is undefined.
This code is from the simple example here:
https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms.openglview?view=xamarin-forms
I see at the top of that example there is the following:
using OpenTK.Graphics.ES30;
But I cannot include this, OpenTK is not recognized as a namespace. I expected to have to add it as a reference, but how?
I can add a reference to it in my .Android project so that I can add the above using statement in my MainActivity.cs page but that is not where it belongs (although I see that I then have GL defined, so this proves that I need to add these using statements to my MainPage.xaml.cs in order to get GL defined), but like I say, how do I add the reference to OpenTK for the project that contains MainPage.xaml.cs.
Thanks for any help,
Mitch.
----- EDIT -----
Thanks to the poster for helping me so far, the new problem is a reference to System.Private.Core that cannot be resolved. Here's the my full workflow for creating this error:
1: Create a new project.
This gives me the three projects:
2: Change to .NET standard 2.1 in the OGLMobile project:
The .Android and .iOS projects don't have a .NET choice option.
3: Add reference to OpenTK to OGLMobile project:
4: OGLMobile project builds fine but .Android project gives:
If I remove reference to OpenTK everything builds again. Makes no difference if I add OpenTK Nuget package to .Android project, I still get the same error.
So close,
thanks for any advice.
You need to install Nuget Package OpenTK.Graphics, then can use that.
Now can refer it:
Note: 4.0.1 of OpenTK.Graphics need .NET Standard 2.1.

How to use Font Awesome in Xamarin.iOS?

I am trying to use Font Awesome Icons in my Xamarin.iOS project.
In my Xamarin.Android project it was pretty simple:
I downloaded the Font Awesome WebKit from here
I copied the .ttf-Files of the fonts I want to use in my Assets folder
I create a new Typeface for my TextView with the font and use the unicode of the icon
Code:
var myIcon = new TextView(Context);
var regularFont = Typeface.CreateFromAsset(Context.Assets, "fonts/fa-regular-400.ttf");
myIcon.SetTypeface(regularFont, TypefaceStyle.Normal);
myIcon.Text = "\uf007";
I can change TextColor, BackgroundColor, etc. like a normal text.
My problem is, I can't figure out, how to use Font Awesome in my Xamarin.iOS project. Most tutorials and How-Tos are directed to Xamarin.Forms. I tried to merge many of these approaches, but it failed.
The only approach I found is to draw the .svg-Files with SkiaSharp, but that is no option for my use case.
Add .ttf files in your Xamarin iOS project (I have added it in resources)
Now inside info.plist Add a new key “Fonts provided by application”
Expand the array, and in string value add your fontname (eg: fa-solid-900.ttf) which you have added in your project
Setup Done:
Now Just wherever you want to add fontawesome icon just select font awesome as font family in storyboard but make sure to add text programmatically
SushiHangovers comment leads me to the solution for my problem.
FontAwesome Pro and xamarin.ios only one font can be active
It was not possible to use 3 Font Awesome fonts at the same time in the Designer, but it works when they are used during runtime via code.

how to implement mapbox correctly in xamarin forms app

i just downloaded the naxam mapbox and am completely lost the github page isn't much of help and there seems to be nothing else can anyone give anything usefull on how to implement the map view in the xamarin.forms app and thanks.
Short Anwser:
The Naxam.Mapbox for Xamarin.Forms Nuget Package, and all the associated Forms ones, have not been update since Sep 12, 2018, and the Mapbox SDK's for Android/iOS have changed since then, i tried this package and it's a bit clunky, i have manage to display the map, but inserting Geojson Sources/ Markers is not a pleasant experience.
EDIT 2019/10/13
Last month, Naxam updated their nuggets to the latest Mapbox version for .Forms, Android and iOS
Long Anwser:
If you really want to use Mapbox in your Xamarin Projects, the Naxam Binding Libraries for Android and iOS are still working today (18/06/2019), So one way to have it working for a Xamarin Forms Project is to implement both sdk's in their respective project, and use them in a Custom View Renderer (and be carefull, because those projects still need other Nuget Packages to work, and they don't warn you when you install them, be sure see the dependecies in the links i gave above).
Other way to have a map in your project is by using MapsUi (Remember that MapsUi is TileBased and Mapbox is VectorBased, so you might see less fluidity while using MapsUi). i will leave here some relevant code for the custom render in iOS for the implementation of MapsUi to get started:
MapViewRenderer.cs
public class MapViewRenderer : ViewRenderer<MapsUIView, Mapsui.UI.iOS.MapControl>
{
Mapsui.UI.iOS.MapControl mapNativeControl;
MapsUIView mapViewControl;
protected override void OnElementChanged(ElementChangedEventArgs<MapsUIView> e)
{
base.OnElementChanged(e);
if (mapViewControl == null && e.NewElement != null)
mapViewControl = e.NewElement;
if (mapNativeControl == null && mapViewControl != null)
{
var rectangle = mapViewControl.Bounds;
var rect = new CGRect(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
mapNativeControl = new Mapsui.UI.iOS.MapControl(rect)
{
Map = mapViewControl.NativeMap,
Frame = rect
};
SetNativeControl(mapNativeControl);
}
}
}
This is the base on how to implement the MapView in a Custom View Render in iOS, similiar code is needed for Android, and of course, the Custom Renderer itself, wich there is tons of tutorials on how to do it, like this ones: Source 1 Source 2

IconToolbarItem with Iconize not click event

I am currently developing a Xamarin.Forms application. I am using IconizePlugin. The app is tabbedPage based and on toolbar I'm trying to include icons for some actions.
This is whay I'm getting:
Icons are showing well and in Xamarin.iOS gets the click event, while it is not working in Xamarin.Droid.
I included the corresponding nugets and followed every steps told in documentation and can't archive this. Other iconize controls in Droid are working fine except the IconToolbarItem.
Please help!
The workaround I found was to declare de IconToolbarItem in the c# code instead of xaml. Although I don't know why it wasn't working while on xaml.
Declaring the item li
ToolbarItems.Add(new IconToolbarItem
{
Icon = "fa-plus",
IconColor = Color.White,
Command = new Command(this.addBono)
});

Unable To Share Text On Xamarin Form

Hello Everyone I want to share the Text on Xamarin Form using Library plugin.share. I have successfully implemented the library and on android i can able to share the text but in iOS it returns me nothing. i have done the share code on button click event so when i click on button in iOS its doesn't returns me anything.i tried the Below code but doesn't got succeed
CrossShare.Current.Share("Hii alll", "Share");
please help me to get out of this,thanks in advance
You want to take a look at UIActivityViewController, you can find the documentation here https://developer.xamarin.com/api/type/MonoTouch.UIKit.UIActivityViewController/
And Xamarin.Forms specific example http://devcenter.wintellect.com/jwood/implementing-sharing-in-xamarin-forms
This is a bit old, but I was having a similar issue and was able to resolve it.
First of all, you need to add the plugin Plugin.Share to ALL Xamarin.Forms projects (Portable, iOS, Android, UWP).
In the class that references the share code, add...
using Plugin.Share;
using Plugin.Share.Abstractions;
CrossShare.Share() doesn't work with strings, directly. You need to new up a ShareMessage.
var title = "Title For The Share";
var message = "Text to share.";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title });
I can't say specifically to iOS, as I don't have a Mac and can't test that project, but Android and Windows 10 is working.

Resources