<pre lang="c#"> using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; using Microsoft.Phone.Controls.Maps; using System.Device.Location; namespace PhoneApp1 { public partial class MainPage : PhoneApplicationPage { // Constructor GeoCoordinateWatcher watcher; Pushpin Pin = new Pushpin(); String bingkey = "Ak3PcwHFqpbSJIES_QnB4Nqs6GMfcjDSkAsl-dgsDzui3UwWs6-lU5Gi1KqYxhu7"; public MainPage() { InitializeComponent(); MAP.CredentialsProvider = new ApplicationIdCredentialsProvider(bingkey); MAP.LogoVisibility = Visibility.Collapsed; MAP.CopyrightVisibility = Visibility.Collapsed; MAP.Mode = new AerialMode(); MAP.Visibility = Visibility.Visible; this.watcher = new GeoCoordinateWatcher(); this.watcher.PositionChanged += new EventHandler<geopositionchangedeventargs><geocoordinate>>(watcher_PositionChanged); bool started = this.watcher.TryStart(false, TimeSpan.FromMilliseconds(2000)); if (!started) { txtStatus.Text=("GeoCoordinateWatcher timed out on start."); } Pin.Location = watcher.Position.Location; MAP.Center = Pin.Location; Ellipse Elip = new Ellipse(); SolidColorBrush mySolidColorBrush = new SolidColorBrush(); // Describes the brush's color using RGB values. // Each value has a range of 0-255. mySolidColorBrush.Color = Colors.Red; Elip.Width=20; Elip.Height = 20; Elip.Name = "locator"; Elip.Fill = mySolidColorBrush; Pin.Content = Elip; txtStatus.Text = String.Format("Acc Horz = {0:0.00} | Acc Vert = {1:0.00}", Pin.Location.HorizontalAccuracy, Pin.Location.VerticalAccuracy); MAP.Children.Add(Pin); } double curLatitude, curLongitude; void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<geocoordinate> e) { curLatitude=e.Position.Location.Latitude; curLongitude = e.Position.Location.Longitude; PrintPosition(curLatitude,curLongitude ); Pin.Location = e.Position.Location; MAP.Children.Remove(Pin); MAP.Center = Pin.Location; MAP.Children.Add(Pin); } void PrintPosition(double Latitude, double Longitude) { txtStatus.Text=("Latitude: "+Latitude+ "Longitude "+ Longitude); } private void button1_Click(object sender, RoutedEventArgs e) { MAP.Mode = new RoadMode(); } private void button2_Click(object sender, RoutedEventArgs e) { MAP.Mode = new AerialMode(); } private void button3_Click(object sender, RoutedEventArgs e) { double zoom; zoom = MAP.ZoomLevel; MAP.ZoomLevel = ++zoom; } private void button4_Click(object sender, RoutedEventArgs e) { double zoom; zoom = MAP.ZoomLevel; MAP.ZoomLevel = --zoom; } private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { } } }</geocoordinate></geocoordinate></geopositionchangedeventargs>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)