amay077 / Xamarin.Forms.GoogleMaps

Map library for Xamarin.Forms using Google maps API
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
MIT License
546 stars 346 forks source link

Label not showing on pin #651

Closed rubenc57 closed 4 years ago

rubenc57 commented 5 years ago

VERSIONS

PLATFORMS

ACTUAL BEHAVIOR

Label is not showing on the pin like normal behavior from googlemaps https://developers.google.com/maps/documentation/javascript/examples/marker-labels

Thank you for your support rubenc

AnthonyLatty commented 5 years ago

Some Code snippet would be helpful to better assist you.

This how you generally add a label to a location

var currentPin = new Pin
{
   Type = PinType.SearchResult,
   Position = new Position(Latitude, Longitude),
   Label = "Current location"
};
rubenc57 commented 5 years ago

Yes I'm doing that:

            var pin = new Pin
            {
                Type = PinType.SearchResult,
                Position = new Position(pos.Latitude, pos.Longitude),
                Label = p.Id,
                Address = p.Address,
                Tag = p.AddressID,
            };

But the label only shows in the infowindow...

AnthonyLatty commented 5 years ago

Ensure the value Label = p.Id is of type string.

rubenc57 commented 5 years ago

Yeah it is, 1 char string This is result (without the label)

Screenshot_1568051386

I'm using string from 1 -9 and A - F

AnthonyLatty commented 5 years ago

Ok to test that it is not the plugin try adding Label = "test" if that display the label "test" then we can assume it is the data that is being send to Label = p.Id

rubenc57 commented 5 years ago

Same result

var pin = new Pin { Type = PinType.SearchResult, Position = new Position(pos.Latitude, pos.Longitude), Label = "test", //p.Id, Address = p.Address, Tag = p.AddressID, };

Screenshot_1568069452

AnthonyLatty commented 5 years ago

Could you comment out Address = p.Address and Tag = p.AddressID? I feel maybe the Tag = p.AddressID is preventing the label from rendering

rubenc57 commented 5 years ago

Same result var pin = new Pin { Type = PinType.SearchResult, Position = new Position(pos.Latitude, pos.Longitude), Label = "test", //p.Id, //Address = p.Address, //Tag = p.AddressID, };

AnthonyLatty commented 5 years ago

Thats strange..

AnthonyLatty commented 5 years ago

Can you submit a small sample so i can take a look to see if its only this project acting up or if its maybe something in your solution.

I just created a replica with the exact nuget packages and everything works fine.

rubenc57 commented 5 years ago

Sure in xaml I have: `

            <maps:Map x:Name="MyMap" 
               MapType="Street" 
               VerticalOptions="FillAndExpand"
               HorizontalOptions="FillAndExpand">
           </maps:Map>

`

in cs i have:

`

    async void PreparingContactsMapPage()
    {

        viewModel.IsBusy = true;

        var currentLocation = await Funciones.ObtenerPosicionActual();

        foreach (var p in cmsDireccionesLista)
        {
            double latitud = p.Latitud, longitud = p.Longitud;
            if (latitud == 0 && longitud == 0)
                continue;
            var pos = new Xamarin.Essentials.Location(latitud, longitud);

            var pin = new Pin
            {
                Type = PinType.SearchResult,
                Position = new Position(pos.Latitude, pos.Longitude),
                Label = p.Id,
                Address = p.Direccion,
                Tag = p.IdDireccion,
            };

            string pinname = string.Empty;

            var item = App.CmsDatabase.CmsDireccionesMapa_GetItem(p.IdDireccion); 

            if (item != null
                && item.IdDireccion == p.IdDireccion)
                pinname = "pingreenaddress.png";
            else
                pinname = "pinredaddress.png";

            pin.Icon = BitmapDescriptorFactory.FromBundle(pinname);

            MyMap.Pins.Add(pin);

            if (currentLocation == null
                || (currentLocation.Latitude == 0
                && currentLocation.Longitude == 0)
                )
                currentLocation = pos;
        }

        if (currentLocation != null)
            MyMap.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom
            (
                new Position(currentLocation.Latitude
                            , currentLocation.Longitude)
                , 15d);

        MyMap.MyLocationEnabled = true;
        MyMap.UiSettings.MyLocationButtonEnabled = true;
        //MyMap.UiSettings.ZoomControlsEnabled = true;
        //MyMap.UiSettings.ZoomGesturesEnabled = true;

        MyMap.InfoWindowClicked += InfoWindow_ClickedAsync;

        MyMap.PinClicked += Pin_Clicked;

        viewModel.IsBusy = false;
    }

` and the cmsDireccionesLista class is:

`

public class DireccionRootObject
{
    public string Id { get; set; }
    public int IdDireccion { get; set; }
    public string UserId { get; set; }
    public string Direccion { get; set; }
    public double Latitud { get; set; }
    public double Longitud { get; set; }
    public DateTime Fecha { get; set; }
    public int Tipo { get; set; }
    public string Nota { get; set; }
    public int Status { get; set; }
    public string StatusDescription { get; set; }
    public int Resultado { get; set; }

}

`

AnthonyLatty commented 5 years ago

Console log the value coming from the class DireccionRootObject maybe the string value is not being passed to Label = p.Id so it wouldnt render on the map. Also check the values in foreach (var p in cmsDireccionesLista)

rubenc57 commented 5 years ago

Remember that we tested with a string directly... Label = "Test" and didn't work

AnthonyLatty commented 5 years ago

Downgrade the version of the Maps plugin and test it and let me know. Also whats the version of XF you are using exactly??

rubenc57 commented 5 years ago

v3.2.1

AnthonyLatty commented 5 years ago

What is the exact version of Xamarin.Forms you are using??

The replica i did i used:

Can you downgrade and test it??

rubenc57 commented 5 years ago

ok, in xamarin.forms I have 4.2.0.778463

rubenc57 commented 5 years ago

But even if it works, I won't be able to downgrade…

rubenc57 commented 5 years ago

I downgrade and same result… no labels shown in pins :(

AnthonyLatty commented 5 years ago

Can you create an empty project with the nuget packages and test alone, thats what i did and i didnt have an issue.

rubenc57 commented 4 years ago

I created an empty project with only this nuget pacakges: NetStandard.Library 2.0.3 Xamarin.Essentials 1.1.0 Xamarin.Forms 4.1.0.555618 Xamarin.Forms.GoogleMaps 3.2.1

In XAML I have `

    <maps:Map x:Name="MyMap" 
            MapType="Street" 
            VerticalOptions="FillAndExpand"
            HorizontalOptions="FillAndExpand">
    </maps:Map>

`

in cs I have:

`

    public MainPage()
    {
        InitializeComponent();
        Map();
    }

    void Map()
    {
        var dirs = new List<DireccionRootObject>();
        var dir = new DireccionRootObject
        {
            Id = "1",
            Latitud = 24.8191,
            Longitud = -107.373
        };

        dirs.Add(dir);
        dir = new DireccionRootObject
        {
            Id = "2",
            Latitud = 24.8166,
            Longitud = -107.3744
        };
        dirs.Add(dir);

        dirs.Add(dir);
        dir = new DireccionRootObject
        {
            Id = "3",
            Latitud = 24.8173,
            Longitud = -107.3745
        };
        dirs.Add(dir);

        //24.8192707,-107.3743718 //las quintas
        var currentLocation = new Xamarin.Essentials.Location(24.8192707, -107.3743718);

        foreach (var p in dirs)
        {
            double latitud = p.Latitud, longitud = p.Longitud;
            if (latitud == 0 && longitud == 0)
                continue;
            var pos = new Xamarin.Essentials.Location(latitud, longitud); // Latitude, Longitude

            var pin = new Pin
            {
                Type = PinType.SearchResult,
                Position = new Position(pos.Latitude, pos.Longitude),
                Label = p.Id,
            };

            MyMap.Pins.Add(pin);

            if (currentLocation == null
                || (currentLocation.Latitude == 0
                && currentLocation.Longitude == 0)
                )
                currentLocation = pos;
        }

        if (currentLocation != null)
            MyMap.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom
            (
                new Position(currentLocation.Latitude
                            , currentLocation.Longitude)
                , 15d);

        MyMap.MyLocationEnabled = true;
        MyMap.UiSettings.MyLocationButtonEnabled = true;
        //MyMap.UiSettings.ZoomControlsEnabled = true;
        //MyMap.UiSettings.ZoomGesturesEnabled = true;
    }

` and I get the same unwanted result :/

Screenshot_1568742268

AnthonyLatty commented 4 years ago

The code seems alright, i cant seem to see whats causing it not to render. Can you post a zip with the solution and i will take a look at that and see whats really happening here?

rubenc57 commented 4 years ago

App8.zip

AnthonyLatty commented 4 years ago

The issue you are having is the label not showing but by default the label is showing it is just not displayed. You have to use the SelectedPin method to show the label for a particular pin. I attached a sample which i did showcasing that below, use the sample and apply that to your code. I commented areas to explain further.

https://send.firefox.com/download/c58a9bf5463d9450/#Po1pfJdaBiqz4rNbUNuRAQ

rubenc57 commented 4 years ago

Thank you for your help That is not my issue, the infowindow it's working fine What I need is the label appearing on the marker Please check this link: https://developers.google.com/maps/documentation/javascript/examples/marker-labels

This should be the result in my case:

Screenshot_1568840194

AnthonyLatty commented 4 years ago

Glad i could help, the title was misleading tho

rubenc57 commented 4 years ago

So the plugin does not render the label on the marker

I had to make the markers one by one and construct the name dynamically: marcador1.png marcador2.png... macadorA.png marcacorB.png etc. If in the future you add this feature would be nice.

Thanks again