English 中文(简体)
• 如何在.网(Android/iOS)获得地图片扫描位置
原标题:How to get a map pins screen position in .net maui (Android/iOS)

I wish to open a popup next to a map pin (when pressed), but cannot figure out how to get the screen position of the Pin.

Adding the Pins to the map works fine:

  map.Pins.Add(nameOfPin);

创建活动手,也是直截了当的:

  nameOfPin.MarkerClicked += OnPinClickedAsync;

下面的活动手应开放Pin的旁边,但我不能获得Pins的屏幕位置。 地图位置包含在标语中,但只要我能知道,屏幕位置就不是。

async void OnPinClickedAsync(object? sender, PinClickedEventArgs args) { var selectedPin = (Pin)sender; . . .and then what?? How to get the Pins screen position (Android/iOS) }

谁能帮助pl?

PS。 我试图补充这次活动所创造的Pin物体的所有信息,但找不到刺丝屏的位置。

问题回答

您可使用MKMapView.Convert Coordinationmeth,该方法可将地图协调成点。

为加以利用,请invoke平台代码

下面的附录是一件pin的点击手,

private void BoardwalkPin1_MarkerClicked(object? sender, PinClickedEventArgs e)
{
    var mypin = sender as Pin;
    float xPos;
    float yPos;

#if IOS
    var vc = UIApplication.SharedApplication.KeyWindow?.RootViewController;
    while(vc.PresentedViewController != null)
    {
        vc = vc.PresentedViewController;
    }

    CLLocationCoordinate2D Coordinate = new CLLocationCoordinate2D(mypin.Location.Latitude, mypin.Location.Longitude);

    var myPoint = (mymap.Handler.PlatformView as MKMapView).ConvertCoordinate(Coordinate,vc.View);
    xPos = (float)myPoint.X;
    yPos = (float)myPoint.Y;
#endif
    Console.WriteLine(xPos);
    Console.WriteLine(yPos);
}

<代码>xPos和yPos,我们获得的是与目前观点相对的位置。

安德森请参看。 • 如何从圆形图2和roid的标识中筛选坐标

希望!





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签