我跟随Microsoft Docs突出显示了地图上的路线。它在一个独立项目上运行完美,我从JSON文件中获得了经度和纬度,并且可以运行,但是当我尝试将其集成到我的主项目中时,它不起作用。
这是我的代码的某些部分:
页面代码:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:interface_test;assembly=interface_test"
x:Class="interface_test.MapPage">
<ContentPage.Content>
<local:CustomMap x:Name="customMap" MapType="Street" WidthRequest="{x:Static local:App.ScreenWidth}" HeightRequest="{x:Static local:App.ScreenHeight}" />
</ContentPage.Content>
</ContentPage>
using Xamarin.Forms;
using Xamarin.Forms.Maps;
namespace interface_test
{
public partial class MapPage1 : ContentPage
{
public MapPage1()
{
InitializeComponent();
for (int i = 0; i < JSONData.GetGlcLatitude1().Count; i++)
{
customMap.RouteCoordinates.Add(new Xamarin.Forms.Maps.Position(JSONData.GetGlcLatitude1()[i], JSONData.GetGlcLongitude1()[i]));
}
for (int i = 0; i < JSONData.GetGlcLatitude2().Count; i++)
{
customMap.RouteCoordinates.Add(new Xamarin.Forms.Maps.Position(JSONData.GetGlcLatitude2()[i], JSONData.GetGlcLongitude2()[i]));
}
customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(JSONData.GetGlcLatitude1()[0], JSONData.GetGlcLongitude1()[0]), Distance.FromMiles(1.0)));
double lat = JSONData.GetiviLatitude();
double lon = JSONData.GetiviLongitude();
var position1 = new Xamarin.Forms.Maps.Position(lat, lon);
var pin1 = new Pin
{
Type = PinType.Place,
Position = position1,
Label = "Current Position",
Address = ""
};
customMap.Pins.Add(pin1);
}
}
}
CustomMap类以获取点列表:
using System.Collections.Generic;
using Xamarin.Forms.Maps;
namespace interface_test
{
public class CustomMap : Map
{
public List<Position> RouteCoordinates { get; set; }
public CustomMap ()
{
RouteCoordinates = new List<Position> ();
}
}
}
使用此代码,我只能得到引脚,而不能得到测试代码中的突出显示路线: ![截图] https://imgur.com/a/f8GycPj