我已经能够打开默认地图应用程序并显示单个位置:
var location = new Location(latitude, longitude);
var options = new MapLaunchOptions { Name = locationName };
try
{
await Map.Default.OpenAsync(location, options);
}
catch (Exception ex)
{
// No map application available to open
}
Run Code Online (Sandbox Code Playgroud)
想知道是否可以打开多个固定位置?
您首先需要加载位置数据,无论是来自嵌入式资源还是 API 调用。一旦您拉入纬度/经度数据(我的数据在列表中),您就可以继续添加它们。您需要map.Layers.Add(CreatePointLayer());调用以下代码:
private MemoryLayer CreatePointLayer()
{
return new MemoryLayer
{
Name = "Points",
IsMapInfoLayer = true,
Features = GetLocsFromList(),
Style = SymbolStyles.CreatePinStyle()
};
}
private IEnumerable<IFeature> GetLocsFromList()
{
var locs = Locs; //<- Locs is the List<Locations>
return locs.Select(l => {
var feature = new PointFeature(SphericalMercator.FromLonLat(l.lng, l.lat).ToMPoint());
return feature;
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
422 次 |
| 最近记录: |