本文整理汇总了C#中Windows.Devices.Geolocation.Geolocator.GetGeopositionAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Geolocator.GetGeopositionAsync方法的具体用法?C# Geolocator.GetGeopositionAsync怎么用?C# Geolocator.GetGeopositionAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Devices.Geolocation.Geolocator
的用法示例。
在下文中一共展示了Geolocator.GetGeopositionAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeMap
/// <summary>
/// Initializes the map.
/// </summary>
private async void InitializeMap()
{
_watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High) { MovementThreshold = 10 };
_watcher.PositionChanged += this.OnPositionChanged;
_watcher.Start();
var geoLocator = new Geolocator { DesiredAccuracyInMeters = 10 };
try
{
Geoposition geoposition = await geoLocator.GetGeopositionAsync(TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(10));
var coordinate = geoposition.Coordinate;
var currentLocation = new GeoCoordinate(
coordinate.Latitude,
coordinate.Longitude,
coordinate.Altitude ?? double.NaN,
coordinate.Accuracy,
coordinate.AltitudeAccuracy ?? double.NaN,
coordinate.Speed ?? double.NaN,
coordinate.Heading ?? double.NaN);
Pushpin pushpin = (Pushpin)this.FindName("UserLocation");
pushpin.GeoCoordinate = currentLocation;
}
catch (Exception)
{
// Inform the user that the location cannot be determined.
App.ViewModel.CurrentLocation = null;
}
}
示例2: obtenerposactual
public async void obtenerposactual() // Metodo que ebtiene la posicion actual del usuario
{
Geolocator migeolocalizador = new Geolocator();
//Geoposition migeoposicion = await migeolocalizador.GetGeopositionAsync();
Geoposition migeoposicion = null;
try
{
migeoposicion = await migeolocalizador.GetGeopositionAsync();
}
catch (Exception ex)
{
if ((uint)ex.HResult == 0x80004004)
{
// the application does not have the right capability or the locatiokn master switch is off
//feedback.Text = "location is disabled in phone settings.";
MessageBox.Show("location is disabled in phone settings.");
}
else
{
// something else happened acquring the location
//feedback.Text = "Something wrong happened";
MessageBox.Show("Something wrong happened");
}
}
Geocoordinate migeocoordenada = migeoposicion.Coordinate;
GeoCoordinate migeoCoordenada = convertidirGeocoordinate(migeocoordenada);
dibujaru(migeoCoordenada);
mimapa.Center = migeoCoordenada;
mimapa.ZoomLevel =11;
cargarlista();
}
示例3: ZoomMap
async void ZoomMap()
{
var geoloc = new Geolocator();
resultsMap.Center = (await geoloc.GetGeopositionAsync()).Coordinate.Point;
resultsMap.ZoomLevel = 15;
}
示例4: GetCoordinates
private async void GetCoordinates()
{
// Get the phone's current location.
Geolocator MyGeolocator = new Geolocator();
MyGeolocator.DesiredAccuracyInMeters = 5;
Geoposition MyGeoPosition = null;
try
{
MyGeoPosition = await MyGeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
MyCoordinates.Add(new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude));
Debug.WriteLine(MyGeoPosition.Coordinate.Latitude + " " + MyGeoPosition.Coordinate.Longitude);
Mygeocodequery = new GeocodeQuery();
Mygeocodequery.SearchTerm = "Hanoi, VN";
Mygeocodequery.GeoCoordinate = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude);
Mygeocodequery.QueryCompleted += Mygeocodequery_QueryCompleted;
Mygeocodequery.QueryAsync();
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Location is disabled in phone settings or capabilities are not checked.");
}
catch (Exception ex)
{
// Something else happened while acquiring the location.
MessageBox.Show(ex.Message);
}
}
示例5: GetMyMapLocationAsync
private async void GetMyMapLocationAsync() {
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try {
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10)
);
Map.Center = new GeoCoordinate(geoposition.Coordinate.Latitude, geoposition.Coordinate.Longitude);
Map.ZoomLevel = ZoomLevel;
myGeoCoordinate = geoposition.Coordinate.ToGeoCoordinate();
myMapOverlay.GeoCoordinate = myGeoCoordinate;
myMapOverlay.Content = new Pushpin() {Content = "You"};
CalculateDistanceBetweenMeAndUser();
} catch (Exception ex) {
if ((uint)ex.HResult == 0x80004004) {
// the application does not have the right capability or the location master switch is off
Debug.WriteLine("Geoposition not allowed or hadrware disabled");
}
//else
{
// something else happened acquring the location
Debug.WriteLine("Geoposition is not available. Failure.");
}
}
}
示例6: GetLocation
public async override Task<Location> GetLocation()
{
var ret = new Location();
// create the locator
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try
{
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10)
);
// THIS IS THE ONLY DIFFERENCE
ret.Latitude = geoposition.Coordinate.Point.Position.Latitude;
ret.Longitude = geoposition.Coordinate.Point.Position.Longitude;
}
catch (Exception ex)
{
if ((uint)ex.HResult == 0x80004004)
{
// the application does not have the right capability or the location master switch is off
}
else
{
// something else happened acquring the location
}
}
// return the location
return ret;
}
示例7: LoadState
/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="navigationParameter">The parameter value passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
/// </param>
/// <param name="pageState">A dictionary of state preserved by this page during an earlier
/// session. This will be null the first time a page is visited.</param>
protected override async void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// Allow saved page state to override the initial item to display
if (pageState != null && pageState.ContainsKey("SelectedItem"))
{
navigationParameter = pageState["SelectedItem"];
}
Geolocator locator = new Geolocator();
Geoposition geoPos = await locator.GetGeopositionAsync();
Geocoordinate geoCoord = geoPos.Coordinate;
String YWSID = "Bi9Fsbfon92vmD4DkkO4Fg";
String url;
if (navigationParameter != "")
{
url = "http://api.yelp.com/business_review_search?term=food&location=" + navigationParameter + "&ywsid=" + YWSID;
}
else
{
url = "http://api.yelp.com/business_review_search?term=food&lat=" + geoCoord.Latitude + "&long=" + geoCoord.Longitude + "&ywsid=" + YWSID;
}
var httpClient = new HttpClient();
String content = await httpClient.GetStringAsync(url);
response = JsonObject.Parse(content);
this.Frame.Navigate(typeof(MainPage),response);
}
示例8: GetLocation
public async Task<Position> GetLocation()
{
if (!Settings.AskedForPermission)
{
var asyncResult = Guide.BeginShowMessageBox("May I get your location from GPS?",
"This application uses your location (GPS) to get the most accurate weather reading",
new[] { "Allow", "Deny" }, 0, MessageBoxIcon.Alert, null, null);
var allowed = await Task.Factory.FromAsync(asyncResult, r => Guide.EndShowMessageBox(r));
Settings.AskedForPermission = true;
Settings.AllowGPS = (allowed.Value != 1);
}
if (!Settings.AllowGPS)
return defaultPosition;
var geolocator = new Geolocator { DesiredAccuracyInMeters = 50 };
var result = new Position();
try
{
Geoposition geoposition = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(10));
result.Lat = geoposition.Coordinate.Latitude;
result.Long = geoposition.Coordinate.Longitude;
}
catch (Exception ex)
{
return defaultPosition;
}
return result;
}
示例9: GetGeoPosition
public static async Task<Geoposition> GetGeoPosition() {
try {
// Request permission to access location
var accessStatus = await Geolocator.RequestAccessAsync();
switch (accessStatus) {
case GeolocationAccessStatus.Allowed:
// Get cancellation token
_cts = new CancellationTokenSource();
CancellationToken token = _cts.Token;
// If DesiredAccuracy or DesiredAccuracyInMeters are not set (or value is 0), DesiredAccuracy.Default is used.
Geolocator geolocator = new Geolocator { DesiredAccuracyInMeters = _desireAccuracyInMetersValue };
// Carry out the operation
_position = await geolocator.GetGeopositionAsync().AsTask(token);
break;
case GeolocationAccessStatus.Denied:
break;
case GeolocationAccessStatus.Unspecified:
break;
}
} catch (TaskCanceledException) {
} catch (Exception) {
} finally {
_cts = null;
}
return _position;
}
示例10: GetCurrentPosition
public async Task<LocationResult> GetCurrentPosition()
{
try
{
var geolocator = new Geolocator()
{
DesiredAccuracyInMeters = 500
};
Geoposition pos = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10)
);
return new LocationResult(new GeoCoordinate(pos.Coordinate.Latitude, pos.Coordinate.Longitude));
}
catch (UnauthorizedAccessException)
{
return new LocationResult("Die aktuelle Position ist zur Berechnung der Distanz zur Messstation notwendig, Zugriff wurde verweigert.");
}
catch (Exception)
{
}
return new LocationResult("Aktuelle Position konnte nicht ermittelt werden");
}
示例11: Context_LocationUpdate
private void Context_LocationUpdate(object sender, ViewModels.Events.LocationUpdateEventArgs e)
{
var ui = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, new Windows.UI.Core.DispatchedHandler(async () =>
{
if (Context.EnableLocate)
{
var accessStatus = await Geolocator.RequestAccessAsync();
if (accessStatus == GeolocationAccessStatus.Allowed)
{
try
{
var _geolocator = new Geolocator();
var pos = await _geolocator.GetGeopositionAsync();
if ((_geolocator.LocationStatus != PositionStatus.NoData) && (_geolocator.LocationStatus != PositionStatus.NotAvailable) && (_geolocator.LocationStatus != PositionStatus.Disabled))
await CalcPosition(pos, Context.cities);
else
{
FailtoPos();
}
}
catch (Exception)
{
FailtoPos();
}
}
else
{
DeniePos();
}
}
CityPanel.Navigate(typeof(CitiesSetting), Context.cities);
}));
}
示例12: GetGeoPosition
//view your location
//get geopostion
public async Task<Geoposition> GetGeoPosition()
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
Geoposition position = await geolocator.GetGeopositionAsync();
return position;
}
示例13: OnNavigatedTo
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// this event is handled for you.
Geolocator geolocator = new Geolocator();
var geo = await geolocator.GetGeopositionAsync();
MapControl1.ZoomLevel = 16;
MapControl1.Center = new Geopoint(new BasicGeoposition()
{
Latitude = geo.Coordinate.Latitude,
Longitude = geo.Coordinate.Longitude
});
List<Locations> locations = await locationsController.GetLocations();
PopulateMap(locations);
AddMapIcon(geo);
}
示例14: GetGpsLocation
private async void GetGpsLocation()
{
// Get the location
try
{
// Get the point
Geolocator m_geoLocator = new Geolocator();
await Geolocator.RequestAccessAsync();
Geoposition position = await m_geoLocator.GetGeopositionAsync();
// Get the address
MapLocationFinderResult mapLocationFinderResult = await MapLocationFinder.FindLocationsAtAsync(position.Coordinate.Point);
if (mapLocationFinderResult.Status != MapLocationFinderStatus.Success)
{
throw new Exception();
}
WeatherSettings.Location loc = new WeatherSettings.Location
{
City = mapLocationFinderResult.Locations[0].Address.Town,
State = mapLocationFinderResult.Locations[0].Address.Region
};
m_settings.CurrentLocation = loc;
ui_locationText.Text = "Your Location: " + mapLocationFinderResult.Locations[0].Address.Town;
// Send the location to the pie
await SendNewSettings(m_settings);
}
catch(Exception)
{
ui_locationText.Text = "Failed to get your location!";
}
}
示例15: ShowMyLocationOnTheMap
private async void ShowMyLocationOnTheMap()
{
Geolocator myGeolocator = new Geolocator();
Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
Geocoordinate myGeocoordinate = myGeoposition.Coordinate;
GeoCoordinate myGeoCoordinate = CoordinateConverter.ConvertGeocoordinate(myGeocoordinate);
this.BettingMap.Center = myGeoCoordinate;
this.BettingMap.ZoomLevel = 15;
Ellipse myCircle = new Ellipse();
myCircle.Fill = new SolidColorBrush(Colors.Blue);
myCircle.Height = 20;
myCircle.Width = 20;
myCircle.Opacity = 50;
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = myCircle;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = myGeoCoordinate;
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay);
BettingMap.Layers.Add(myLocationLayer);
}