posts - 82, comments - 0, trackbacks - 0

My Links



Post Categories

C# Download


Informativa cookie



Msdn Gallery



Wiki Tecknet

BingMap Sample with MetroStyle Application.

In this example we will see how to use the Map control in a Metro application.

To try this example and request the release of ConsumerPreviwe Windows8, edit it for VisualStudio 11 Beta, at least the express version that includes templates for Metro Style and Aplications BingMap an account, you can activate this

Metro and the new interface introduced by Microsoft with the new operating system still in Windows8 ConsumerPreview. One of the novelties of this interface and the introduction of WinRt. By WinRt (Windows Runtime) and can use and interact with the operating system in a considerably simpler and more intuitive using the namespace System.Windows. In the past, to interact directly with the native Windows DLLs must often resort to the use of the Api, it was necessary to manage the Marshaling and others being very careful to maintain the code to avoid malfunctions that put a big risk even in some cases the stability the operating system itself. In this example we will see also Geolocator Class included in the namespace System.Device.Geolocation.

//Calling dll framework 4.5
using System;
using Bing.Maps;
using Windows.Devices.Geolocation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at

//NameSpace BingMapSample
namespace BingMapSample
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class BlankPage : Page
        //Public Constructor of BlankPage
        public BlankPage()
            //InitializeComponent Method

        /// <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.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)

        //ClickEvent btnFidnPosition button
        private async void btnFidnPosition(object sender, RoutedEventArgs e)
            //Declare new Intance of Geolocator Class
            var location = new Geolocator();

            /* Retrieval asynchronously to the location where we are, how can you see the word async which indicate
             * that the invoked method executes his work so as not to block the application and then suspend it temporarily,
             * but does everything in the background and returns the result in the operation is finished. All functions that
             * take more than 50 ms with WinRt asynchronous operations are defined.*/
            var myposition = await location.GetGeopositionAsync();

            /*Center with the property we set the latitude and longitude retrieved using the method Asynchronous
             * GetGeopositionAsync we see our actual position. How can we see through the Location class two parameters,
             * latitude and longitude.*/
            BingMapSample.Center = new Location(myposition.Coordinate.Latitude, myposition.Coordinate.Longitude);

            /*This property allows us to set an enumeration using the display mode of the map, we have three mode,
             * Aerial, and Birdseye Road.*/
            BingMapSample.MapType = MapType.Road;

            /*On the inside of these two controls and we enter the latitude and longitude
             * of the location where we are, the two properties mdiante latitude and longitude.*/
            txtLatitude.Text = myposition.Coordinate.Latitude.ToString();
            txtLongitude.Text = myposition.Coordinate.Longitude.ToString();


Before you run the application and necessary to enable the use of certain operating system resources, in our case we will go through the capabilities to enable the resource Location, this by double clicking with the mouse on the file Pakage.appxmanifest, select tabs Capabilities.
When you first start the application you will be asked to confirm with a dialog box 's permission to start searching for your location from our device. We confirm the authorization so that you can immediately test the application and get the location of latitude and longitude.
The application has been tested with the simulator available with VisualStudio 11 Beta.

Print | posted on mercoledì 25 aprile 2012 15:25 | Filed Under [ Articles C# in English ]


No comments posted yet.

Post Comment

Please add 2 and 7 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET