The Bing Maps Silverlight Control

0
99

Alternatively, for a more immersive experience, you can use the Bing Maps Silverlight Control for Windows Phone. This control allows users to search for locations and interact with the map using tap, stretch, pinch, and pan gestures. It also gives you a great deal of control over how the map is displayed, the centered location, the view it displays (such as Aerial, Birdseye, or Road), the zoom level, and much more. In addition, you can handle events exposed by the control within your
application to interact with the user if required.

Note: You must register and obtain a key from the Bing Maps Account Center from the Bing page on Microsoft.com (http://www.microsoft.com/maps/developers/) in order to use Bing Maps in your applications. If you do not specify a valid key for the Bing Maps control in your application, it displays a message that the credentials are invalid.

As an example, if you have established the current location of the device using a GeoCoordinateWatcher, as described earlier in this section, you can display a map using the Bing Maps control embedded in a page of your application. The following code example sets the properties of a Bing Maps control to display a specific location. It sets the zoom level to 12 and displays the controls for zooming in and out and the scale indicator.

C#
Location loc = new Location();
loc.Latitude = watcher.Position.Location.Latitude;
loc.Longitude = watcher.Position.Location.Longitude;
loc.Altitude = watcher.Position.Location.Altitude;
double zoom = 12.0;
myMapControl.ScaleVisibility = System.Windows.Visibility.Visible;
myMapControl.ZoomBarVisibility = Visibility.Visible;
myMapControl.SetView(loc, zoom);

To use the Bing Maps control, you must reference the corresponding namespaces in your application. The minimum set is Microsoft. Phone.Controls.Maps, Microsoft.Phone.Controls.Maps.Design, and Microsoft.Phone.Controls.Maps.Platform. If you use the extended features of the MapCore class that implements the Bing Maps control, you may also require the namespaces Microsoft.Phone. Controls.Maps.AutomationPeers, Microsoft.Phone.Controls.Maps.Core, and Microsoft.Phone.Controls.Maps.Overlays.

For more information about using the Bing Maps control to provide an interactive mapping experience for users of your application, see “Bing Maps Silverlight Control for Windows Phone” on MSDN (http://msdn.microsoft.com/en-us/library/ff941096(VS.92).aspx).