Search code examples
azure-maps

Azure map rendering - pin name can't have a '


I am using Azure.Maps.Rendering and found a bug with the following:

public async Task<byte[]> GetMapThumbnailAsync(string? name, double longitude, double latitude)
{

    var pushPins = new List<ImagePushpinStyle>();
    if (!string.IsNullOrEmpty(name))
    {
        var position = new PushpinPosition(longitude, latitude, name);
        var pushpinSet = new ImagePushpinStyle(new List<PushpinPosition>() { position })
        {
            PushpinScaleRatio = 0.8, //1.2,
            PushpinColor = Color.Red,
            LabelColor = Color.Green,
            LabelScaleRatio = 10 //18
        };
        pushPins.Add(pushpinSet);
    }

I initially passed in a name of "Dave's home" and that threw an exception of:

{"pins":["Invalid format for location value ''Dave's home'-105.13008 39.98274'. Expected a floating-point longitude between -180 and 180."]}

So, how do I pass in a ' in the name?

And are there any other characters that will cause it to fail?


Solution

  • I believe this is a limitation of that service as it uses single quotes to wrap the name value. I tried a lot of workarounds and none of them worked. You could try a tilda (`). Here is what that ends up looking like:

    enter image description here

    As provided in the comment thread, here is a simple bit of code you can add that will replace single quotes with a tilda in your name string.

    name = name.Replace("'", "\u2019");