MainPage.xaml
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ExperimentTitle" Text="ExpNo MC8" TextAlignment="Right" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="ApplicationTitle" Text="Mobile Computing" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Geo-Coordinates using Map" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Margin="12,149,12,12" Grid.RowSpan="2">
<my:Map Height="462" CredentialsProvider="Your Bing Map Key"
HorizontalAlignment="Left" Margin="6,6,0,0" Name="map1" VerticalAlignment="Top" Width="444" />
<Button Content="Road Mode" Height="72" HorizontalAlignment="Left" Margin="6,474,0,0" Name="buttonRoad" VerticalAlignment="Top" Width="207" Click="buttonRoad_Click" />
<Button Content="Aerial Mode" Height="72" HorizontalAlignment="Left" Margin="243,474,0,0" Name="buttonAerial" VerticalAlignment="Top" Width="207" Click="buttonAerial_Click" />
<Button Content="Zoom In" Height="72" HorizontalAlignment="Left" Margin="6,535,0,0" Name="buttonZoomIn" VerticalAlignment="Top" Width="207" Click="buttonZoomIn_Click" />
<Button Content="Zoom Out" Height="72" HorizontalAlignment="Left" Margin="243,535,0,0" Name="buttonZoomOut" VerticalAlignment="Top" Width="207" Click="buttonZoomOut_Click" />
</Grid>
</Grid>
|
Exp No MC8(Experiment title)
Mobile Computing(Application title)
Geo-Coordinates using Map(Page Title)
Road Mode(button)
Aerial Mode (button)
Zoom In(button)
Zoom Out(button)
|
MainPage.xaml.cs
using System;
using System.Windows;
using Microsoft.Phone.Controls.Maps;
using Microsoft.Phone.Controls;
using System.Device.Location;
namespace MobileComputingTest
{
public partial class MainPage : PhoneApplicationPage
{
GeoCoordinateWatcher myWatcher;
// Constructor
public MainPage()
{
InitializeComponent();
myWatcher = new GeoCoordinateWatcher();
myWatcher.Start();
myWatcher.PositionChanged+=new EventHandler<GeoPositionChangedEventArgs
<GeoCoordinate>>(myWatcher_PositionChanged);
}
private void myWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs
e) {
ApplicationTitle.Text = String.Format("Latitude:{0}, Longitude:{1}",e.Position.Location.Latitude,
e.Position.Location.Longitude);
map1.Center = new GeoCoordinate(e.Position.Location.Latitude,
e.Position.Location.Longitude);
map1.ZoomLevel = 6;
Pushpin pin = new Pushpin();
pin.Location = new GeoCoordinate(e.Position.Location.Latitude,
e.Position.Location.Longitude);
map1.Children.Add(pin);
}
private void buttonRoad_Click(object sender, RoutedEventArgs e)
{
map1.Mode = new RoadMode();
//map1.Center = new GeoCoordinate();
}
private void buttonAerial_Click(object sender, RoutedEventArgs e)
{
map1.Mode = new AerialMode();
}
private void buttonZoomIn_Click(object sender, RoutedEventArgs e)
{
double zoom;
zoom = map1.ZoomLevel;
map1.ZoomLevel = ++zoom;
}
private void buttonZoomOut_Click(object sender, RoutedEventArgs e)
{
double zoom;
zoom=map1.ZoomLevel;
map1.ZoomLevel = --zoom;
}
}
}
|
Add Reference Microsoft.Phone.Controls.Maps and System.Device.Location
Instantiate GeoCoordinateWatcher
Body of myWatcher_PositionChanged(){}
Priniting Geocoordinate
Setting the GeoCoordinate on the Map
Displaying RoadMode() view on the Map.
Displaying AerialMode() view on the Map.
Zoom In(button)
Zoom Out(button)
|