Some useful stuff to start with – Windows Phone Maps and Location Services

Speaking about maps, much has yet to be done. Not by Microsoft or Nokia themselves, but by developers instead. Maps and their APIs are mature enough, yet developers are feared by them or have no idea of what to create of useful using them.

Starting from the basics, you can actually control the sources the Geolocation Service uses. You can set the DesiredAccuracy property of the Geolocator object:
– PositionAccuracy.High – if you want the most accurate data available, but at the cost of increased battery usage, network bandwidth and possibly monetary charges from wireless network operators. Often this causes the GPS to be activated
– PositionAccuracy.Default – to optimize for power
You can also set the DesiredAccuracyInMeters property to indicate to the Geolocation service the desired accuracy of any results. However, the Geolocation service determinates the best location data to provide to the application.


After all this theory, we can actually start writing some code, and what’s better than a piece of code that, at the pression of a button, fills some textblocks with the current phone location?

Here we go:

Private async void Button_Click(object sender, RoutedEventsArgs e){
     Geolocator geolocator = new Geolocator();
     geolocator.DesideredAccuracyInMeters = 50;
     try {
          Geoposition geoposition = await geolocator.GetGeopositionAsync(
          maximumAge: TimeSpan.FromMinutes(5),
          timeout: TimeSpan.FromSeconds(10) );
          LatitudeTextBlock.Text = geoposition.Coordinate.Latitute.ToString("0.00");
          LongitudeTextBlock.Text = geoposition.Coordinate.Longitude.ToString("0.00");
     catch (UnauthorizedAccessException){
          //the app does not have the right capability or location is turned off
          StatusTextBlock.Text = "error";

As already pointed out, this code will actually return you, respectively in the LatitudeTextBlock and LongitudeTextBlock, the correct Latitude and Longitude of the phone, unless an error is detected and caught.

More to come about geolocation, stay tuned and Happy Coding! đŸ™‚


Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:


Stai commentando usando il tuo account Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.