2012-03-15 114 views

回答

0

我希望this来帮助你。简而言之,您必须使用对象GeoCoordinateWatcher

private void startLocationButton_Click(object sender, RoutedEventArgs e) 
{ 
    if (watcher == null) 
    { 
     watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default); 
     watcher.MovementThreshold = 20; 
     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: 
      MessageBox.Show("Location Service is not enabled on the device"); 
      break; 

     case GeoPositionStatus.NoData: 
      MessageBox.Show(" The Location Service is working, but it cannot get location data."); 
      break; 
    } 
} 

void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) 
{ 
    if (e.Position.Location.IsUnknown) 
    { 
     MessageBox.Show("Please wait while your prosition is determined...."); 
     return; 
    } 
} 
相关问题