我想在使用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;
我想解决这个问题,或者在点击时添加引脚的任何其他想法
我在我的演示中使用了你的代码,我得到的结果如下面的截图(如果你看不到google
的乐队,你应该检查API_KEY
,如果它是正确的。)
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="API_KEY" />
然后我将lit
更改为37,将longt
更改为-122并在点击时添加引脚。我可以看到地图并获得以下结果。如果价值合法,请检查您的lit
和longt
有我的代码。
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这可以帮到你。