【发布时间】:2018-03-14 11:03:11
【问题描述】:
在 Xamarin 表单中,我使用谷歌地图插件来显示某些位置。 对于每个位置的图钉,我想显示一个 url 以及标签和地址,以便用户可以单击该 url 并打开一个信息页面。
我创建了一个自定义 pin 以包含 url,但我不知道如何在 pin 上显示它。
有人知道怎么做吗?
public partial class MapPage : ContentPage
{
public List<CustomPin> CustomPins { get; set; }
public MapPage()
{
InitializeComponent();
PlotPositions();
MyMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(lat, long), Distance.FromMiles(1.0)));
}
public void PlotPositions()
{
var myPos = new Position(lat, long);
var pin = new CustomPin
{
Type = PinType.Place,
Position = myPos,
Label = "Glasgow City Centre",
Address = "Argle Street, Glasgow",
Url = "testUrl"
};
MyMap.Pins.Add(pin);
}
public class CustomPin : Pin
{
public string Id { get; set; }
public string Url { get; set; }
}
}
internal class CustomPin
{
public PinType Type { get; set; }
public Position Position { get; set; }
public string Label { get; set; }
public string Url { get; set; }
}
地图页面:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
x:Class="gl_mobile_app.Views.Map.MapPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="back" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
<Grid BackgroundColor="Gray">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Grid.Row="0" Padding="20,20,20,20">
<maps:Map
x:Name="MyMap"
IsShowingUser="True"
MapType="Street"
/>
</StackLayout>
</Grid>
</ContentPage.Content>
</ContentPage>
【问题讨论】:
标签: c# google-maps xamarin.forms