单击Xamarin.Forms.Maps添加引脚

问题描述 投票:0回答:1

我想在使用Xamarin.Forms.Maps点击地图时添加一个新引脚。搜索之后,我发现我必须使用TKCustomMap插件..但它没有在地图上显示..只是空区域,这是我的代码

   double lit = 2.394;// double.Parse(Center.CenterLocationX);
   double longt = 43.2352;// double.Parse(Center.CenterLocationY);
   TK.CustomMap.Position position = new TK.CustomMap.Position(lit, longt);
   TK.CustomMap.MapSpan span = TK.CustomMap.MapSpan.FromCenterAndRadius(position, TK.CustomMap.Distance.FromMiles(0.5));

   TK.CustomMap.TKCustomMap map = new TK.CustomMap.TKCustomMap(span);
   map.IsShowingUser = true;
   map.MapType = TK.CustomMap.MapType.Street;
   TK.CustomMap.TKCustomMapPin pin = new TK.CustomMap.TKCustomMapPin()
   {
        //Address = "Test",
        //Label = "Test",
        Position = position,
        IsDraggable = true
        //Type = PinType.SearchResult
    };
    map.MapClicked += (x, y) =>
    {
        SharedTools.MakeToast("Clicked");
    };
    //map.Pins.Add(pin);
    map.Pins = new List<TK.CustomMap.TKCustomMapPin>() { pin };

    map.MoveToMapRegion(span);
    layout.Content = map;

我想解决这个问题,或者在点击时添加引脚的任何其他想法

c# xamarin.forms maps
1个回答
0
投票

我在我的演示中使用了你的代码,我得到的结果如下面的截图(如果你看不到google的乐队,你应该检查API_KEY,如果它是正确的。)

<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="API_KEY" />

enter image description here

然后我将lit更改为37,将longt更改为-122并在点击时添加引脚。我可以看到地图并获得以下结果。如果价值合法,请检查您的litlongt

enter image description here

有我的代码。

public partial class MainPage : ContentPage
{
    TK.CustomMap.TKCustomMap map;
    TK.CustomMap.Position position;
    public MainPage()
    {
        InitializeComponent();
        //37,-122
        double lit = 37;// double.Parse(Center.CenterLocationX);
        double longt = -122;// double.Parse(Center.CenterLocationY);
        position = new TK.CustomMap.Position(lit, longt);
        TK.CustomMap.MapSpan span = TK.CustomMap.MapSpan.FromCenterAndRadius(position, TK.CustomMap.Distance.FromMiles(0.5));
        map = new TK.CustomMap.TKCustomMap(span);
        map.IsShowingUser = true;
        map.MapType = TK.CustomMap.MapType.Street;
        map.MapClicked += OnMapClicked;
        Content = map;
    }
    private void OnMapClicked(object sender, TKGenericEventArgs<Position> e)
    {
        TK.CustomMap.TKCustomMapPin pin = new TK.CustomMap.TKCustomMapPin()
        {
            //Address = "Test",
            //Label = "Test",
            Position = position
        ,
            IsDraggable = true
            //Type = PinType.SearchResult
        };

        map.Pins = new List<TK.CustomMap.TKCustomMapPin>() { pin };

    }
}   

这是我的demo.Hope这可以帮到你。

https://github.com/851265601/TKGoogleMapsDemo

© www.soinside.com 2019 - 2024. All rights reserved.