이 코드를 사용해보십시오. 위치 서비스에서 데이터를 가져오고 위치 서비스 상태가 변경되면 변경 알림을 발생시킵니다. 이 코드의 경우 msdn
using System.Device.Location;
// Click the event handler for the “Start Location” button.
private void startLocationButton_Click(object sender, RoutedEventArgs e)
{
// The watcher variable was previously declared as type GeoCoordinateWatcher.
if (watcher == null)
{
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); // using high accuracy
watcher.MovementThreshold = 20; // use MovementThreshold to ignore noise in the signal
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
}
watcher.Start();
}
void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
switch (e.Status)
{
case GeoPositionStatus.Disabled:
// The Location Service is disabled or unsupported.
// Check to see whether the user has disabled the Location Service.
if (watcher.Permission == GeoPositionPermission.Denied)
{
// The user has disabled the Location Service on their device.
statusTextBlock.Text = "you have this application access to location.";
}
else
{
statusTextBlock.Text = "location is not functioning on this device";
}
break;
case GeoPositionStatus.Initializing:
// The Location Service is initializing.
// Disable the Start Location button.
startLocationButton.IsEnabled = false;
break;
case GeoPositionStatus.NoData:
// The Location Service is working, but it cannot get location data.
// Alert the user and enable the Stop Location button.
statusTextBlock.Text = "location data is not available.";
stopLocationButton.IsEnabled = true;
break;
case GeoPositionStatus.Ready:
// The Location Service is working and is receiving location data.
// Show the current position and enable the Stop Location button.
statusTextBlock.Text = "location data is available.";
stopLocationButton.IsEnabled = true;
break;
}
}
'작동하지 않는다'는 것은 무엇입니까? –
@igral OnNavigatedTo 메서드에서 위의 코드를 붙여 넣었습니다. 페이지가로드 될 때 위치가 활성화되어 있지 않다는 메시지가 항상 나타납니다. – JIKKU