다음을 통해 공유


GeoCoordinateWatcher.OnPositionChanged 메서드

정의

PositionChanged 이벤트가 발생할 때 호출됩니다.

protected:
 void OnPositionChanged(System::Device::Location::GeoPositionChangedEventArgs<System::Device::Location::GeoCoordinate ^> ^ e);
protected void OnPositionChanged (System.Device.Location.GeoPositionChangedEventArgs<System.Device.Location.GeoCoordinate> e);
member this.OnPositionChanged : System.Device.Location.GeoPositionChangedEventArgs<System.Device.Location.GeoCoordinate> -> unit
Protected Sub OnPositionChanged (e As GeoPositionChangedEventArgs(Of GeoCoordinate))

매개 변수

e
GeoPositionChangedEventArgs<GeoCoordinate>

새 위치를 포함하는 GeoPositionChangedEventArgs<T> 개체입니다.

예제

다음 프로그램의 지속적인 업데이트를 구독 하는 방법을 보여 줍니다 PositionChanged 이벤트입니다.

using System;
using System.Device.Location;

namespace GetLocationEvent
{
    class AsyncProgram
    {
        static void Main(string[] args)
        {
            CLocation myLocation = new CLocation();
            myLocation.GetLocationEvent();
            Console.WriteLine("Enter any key to quit.");
            Console.ReadLine();
        }
        class CLocation
        {
            GeoCoordinateWatcher watcher;

            public void GetLocationEvent()
            {
                this.watcher = new GeoCoordinateWatcher();
                this.watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
                bool started = this.watcher.TryStart(false, TimeSpan.FromMilliseconds(2000));
                if (!started)
                {
                    Console.WriteLine("GeoCoordinateWatcher timed out on start.");
                }
            }

            void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
            {
                PrintPosition(e.Position.Location.Latitude, e.Position.Location.Longitude);
            }

            void PrintPosition(double Latitude, double Longitude)
            {
                Console.WriteLine("Latitude: {0}, Longitude {1}", Latitude, Longitude);
            }
        }
    }
}
Imports System.Device.Location

Module GetLocationEvent
    Public Class CLocation
        Private WithEvents watcher As GeoCoordinateWatcher
        Public Sub GetLocationEvent()
            watcher = New System.Device.Location.GeoCoordinateWatcher()
            AddHandler watcher.PositionChanged, AddressOf watcher_PositionChanged
            Dim started As Boolean = watcher.TryStart(False, TimeSpan.FromMilliseconds(1000))

            If Not started Then
                Console.WriteLine("GeoCoordinateWatcher timed out on start.")
            End If
        End Sub

        Private Sub watcher_PositionChanged(ByVal sender As Object, ByVal e As GeoPositionChangedEventArgs(Of GeoCoordinate))
            PrintPosition(e.Position.Location.Latitude, e.Position.Location.Longitude)
        End Sub

        Private Sub PrintPosition(ByVal Latitude As Double, ByVal Longitude As Double)
            Console.WriteLine("Latitude: {0}, Longitude {1}", Latitude, Longitude)
        End Sub
    End Class


    Public Sub Main()
        Dim myLocation As New CLocation()
        myLocation.GetLocationEvent()
        Console.WriteLine("Enter any key to quit.")
        Console.ReadLine()
    End Sub

End Module

적용 대상