首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在毛伊岛的MAPSUI中打开带有引脚的当前位置图。我需要在我的毛伊岛应用程序上显示地图

如何在毛伊岛的MAPSUI中打开带有引脚的当前位置图。我需要在我的毛伊岛应用程序上显示地图
EN

Stack Overflow用户
提问于 2022-06-24 04:47:56
回答 1查看 606关注 0票数 1

正如我已经尝试了下面的代码为MAPSUI获得映射,但它是无效的。新mapView.MyLocationLayer.UpdateMyLocation(e.Latitude,e.Longitude);

EN

回答 1

Stack Overflow用户

发布于 2022-07-12 14:47:12

我可以得到地图,但没有其他,我不确定我是否真的做得对。

然而,

在我的xaml中

代码语言:javascript
复制
//headers

...
<ContentView x:Name="mapView">

</ContentView>

在我后面的代码中(因为MVVM可能还没有工作)

代码语言:javascript
复制
using Location = Microsoft.Maui.Devices.Sensors.Location;

namespace xxx

public partial class MainPage : ContentPage
{

  IGeolocation geolocation;

  public Location location;

  public MainPage(MainPageViewModel viewModel, IGeolocation geolocation)
    {
        InitializeComponent();
    BindingContext = viewModel;

    this.geolocation = geolocation;
    location = new();
    GetLocation();
  }

  //follow the example at https://www.youtube.com/watch?v=eRXiiy800XY&list=PLfbOp004UaYVt1En4WW3pVuM-vm66OqZe&index=9 for getting the location

  public async void GetLocation()
  {
    try
    {
      location = await geolocation.GetLocationAsync(new GeolocationRequest
      {
        DesiredAccuracy = GeolocationAccuracy.Best,
        Timeout = TimeSpan.FromSeconds(30)
      });

//now for mapsui
      var smc = SphericalMercator.FromLonLat(location.Longitude, location.Latitude);
      
      var mapControl = new Mapsui.UI.Maui.MapControl();
      var map = mapControl.Map;
      map?.Layers.Add(Mapsui.Tiling.OpenStreetMap.CreateTileLayer());
      
      map.Widgets.Add(new ZoomInOutWidget { MarginX = 10, MarginY = 20 });  //adds the +/- zoom widget

      map.Home = n => n.NavigateTo(new MPoint(smc.x, smc.y), map.Resolutions[16]);  //0 zoomed out-19 zoomed in


      //Add this to my xaml
      mapView.Content = mapControl;
      




    }
    catch (Exception e)
    {
      Debug.WriteLine($"GM: Can't query location: {e.Message}");
    }
  }

}

您可能需要允许导入一些mapsui.xxxx

现在,我从悲惨的文档中注意到,有一种观点认为,Xamarin表单使用并应该在Maui中使用。

代码语言:javascript
复制
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             
             xmlns:mapsui="clr-namespace:Mapsui.UI.Maui;assembly=Mapsui.UI.Maui"
             
             xmlns:local="clr-namespace:RouteIt.ViewModels"
             x:Class="RouteIt.MainPage">
...

  <mapsui:MapView x:Name="mapView" />

</ContentPage>

这显示了一个稍微不同的(更好的)视图的轮廓,但我找不到神奇的咒语,使地图出现。

我希望这能帮上忙。

G

编辑,30秒后,在我发现的下一篇文章中

代码语言:javascript
复制
<mapsui:MapView x:Name="mapView" />

在代码中

代码语言:javascript
复制
mapView.Map = map;

当你知道怎么做的时候很明显!

按照https://www.youtube.com/watch?v=eRXiiy800XY&list=PLfbOp004UaYVt1En4WW3pVuM-vm66OqZe&index=9编辑位置

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72739111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档