Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call an asynchronous method?
    primarykey
    data
    text
    <p>I am trying to do a simple app that gets the current location in windows 8, but I cant find the correct syntax of the await keyword.</p> <p>The error says: Error 1 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. </p> <p>The code is as follows:</p> <pre><code>public MainPage() { this.InitializeComponent(); TextBlock txt = new TextBlock(); var location = await InitializeLocationServices(); txt.Text = location; Grid.SetRow(txt, 0); Grid.SetColumn(txt, 1); //InitializeLocationServices(); } /// &lt;summary&gt; /// Invoked when this page is about to be displayed in a Frame. /// &lt;/summary&gt; /// &lt;param name="e"&gt;Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.&lt;/param&gt; protected override void OnNavigatedTo(NavigationEventArgs e) { } private async Task&lt;string&gt; InitializeLocationServices() { //Initialize geolocator object Geolocator geoLocator = new Geolocator(); if (null != geoLocator) try { //Try resolve the current location var position = await geoLocator.GetGeopositionAsync(); if (null != position) { string city = position.CivicAddress.City; string country = position.CivicAddress.Country; string state = position.CivicAddress.State; string zip = position.CivicAddress.PostalCode; string msg = "I am located in " + country; if (city.Length &gt; 0) msg += ", city of " + city; if (state.Length &gt; 0) msg += ", " + state; if (zip.Length &gt; 0) msg += " near zip code " + zip; return msg; } return string.Empty; } catch (Exception) { //Nothing to do - no GPS signal or some timeout occured.n . return string.Empty; } return string.Empty; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload