Closed rubenc57 closed 4 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"
};
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...
Ensure the value Label = p.Id
is of type string.
Yeah it is, 1 char string This is result (without the label)
I'm using string from 1 -9 and A - F
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
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, };
Could you comment out Address = p.Address
and Tag = p.AddressID
? I feel maybe the Tag = p.AddressID
is preventing the label from rendering
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, };
Thats strange..
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.
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; }
}
`
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)
Remember that we tested with a string directly...
Label = "Test"
and didn't work
Downgrade the version of the Maps plugin and test it and let me know. Also whats the version of XF you are using exactly??
v3.2.1
What is the exact version of Xamarin.Forms you are using??
The replica i did i used:
Can you downgrade and test it??
ok, in xamarin.forms I have 4.2.0.778463
But even if it works, I won't be able to downgrade…
I downgrade and same result… no labels shown in pins :(
Can you create an empty project with the nuget packages and test alone, thats what i did and i didnt have an issue.
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 :/
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?
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
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:
Glad i could help, the title was misleading tho
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
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