A group blog from members of the VB team
In our previous post, I explained how to create an application bar for Windows Phone 7. Bing Maps is one of the applications that is commonly used on phones these days. In this blog post, I want to share a sample that will help you to create a Bing Maps application for Windows Phone 7. This application will provide the feature to view maps in road view and aerial view. This application will also provide the zooming in and zooming out features.
I will now demonstrate how easy it is to create a Bing Maps application for Windows Phone 7, using Visual Basic for Windows Phone Developer Tools. The Bing Maps application can be created in 4 simple steps as follows:
Prerequisites:
To create the Bing maps application, let’s follow the 4 simple steps mentioned earlier:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<my:Map Height="462" HorizontalAlignment="Left" Margin="6,6,0,0" Name="map1" VerticalAlignment="Top" Width="444" />
<Button Content="Zoom In" Height="72" HorizontalAlignment="Left" Margin="6,535,0,0" Name="buttonZoomIn" VerticalAlignment="Top" Width="207" />
<Button Content="Road Mode" Height="72" HorizontalAlignment="Left" Margin="6,474,0,0" Name="buttonRoad" VerticalAlignment="Top" Width="207" />
<Button Content="Zoom Out" Height="72" HorizontalAlignment="Left" Margin="243,535,0,0" Name="buttonZoomOut" VerticalAlignment="Top" Width="207" />
<Button Content="Aerial Mode" Height="72" HorizontalAlignment="Left" Margin="243,474,0,0" Name="buttonAerial" VerticalAlignment="Top" Width="207" />
</Grid>
Your application now looks like this:
Adding event handlers is one of the important tasks. These event handlers are required to switch the map modes from aerial view to road view and vice versa when the appropriate button is clicked.
To add the event handlers:
Private Sub buttonRoad_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
map1.Mode = New RoadMode()
End Sub
Private Sub buttonAerial_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
map1.Mode = New AerialMode()
Private Sub buttonZoomIn_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim zoom = map1.ZoomLevel
zoom += 1
map1.ZoomLevel = zoom
Private Sub buttonZoomOut_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
zoom -= 1
Now your Bing Maps application for Windows Phone 7 is ready! You just need to build and debug the application.
Note: To stop debugging the application, select Debug > Stop Debugging.
Your Bing Maps application for Windows Phone 7 is ready to be published into the marketplace. Now, you just need to rebuild your application for the release.
Finally, to submit your application to the market place, you can refer to upload your application walkthrough.
That’s it! We’ve now seen that creating a Bing Maps application for Windows Phone 7 isn’t that tough. In fact, you’ve created it in just 4 simple steps!
You can find the full source code for the application here.
Can you please highlight on how to add pushpin on bing map?