The fist task in hand if you want to use map controls or any other map services(drive service , walk service and more ) in your app is to authenticate your app to use the map services and this needs to be done in the windows phone developer dashboard .
Here is the Link which will guide you to Authenticate your app to work with maps .
Once done with the above step you will get your Map service ApplicationID and Map service AuthenticationToken .
The Maps controls for windows phone 8.1 WINRT application resides in the Windows.UI.Xaml.Controls.Maps namespace.
below is the simple code snippet to add map control to the page.
<grid background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<grid margin="12,0,12,0">
<grid .rowdefinitions="">
<rowdefinition height="Auto">
<rowdefinition height="*">
</rowdefinition></rowdefinition></grid>
<textblock fontsize="30" grid.row="0" margin="0,12,0,12" text="My Maps" textwrapping="Wrap">
<maps:mapcontrol grid.row="1" mapservicetoken="Your Map service AuthenticationToken" maptapped="MyMap_MapTapped" x:name="MyMap">
</maps:mapcontrol></textblock></grid>
</grid>
** you need to use the Map service AuthenticationToken for the MapServiceToken property of the maps control .
There are many properties available on the Maps control which allows the developer to customize the behavior and also the look and feel of the maps when it renders ,
we will see how to work with some of the most commonly used properties .
we will see how to work with some of the most commonly used properties .
Set/Get the location in the map
use the Center property of the maps to Set/Get the location in the map , the Center Property is of the type Geopoint .MyMap.Center = new Geopoint(new BasicGeoposition() { Latitude = 100.604, Longitude = -12.329 });
** you can also use Databind to directly bind the value to the XAML control
Set/Get the Zoom Level in the map
you can Set/Get the zoom level of your map control with the ZoomLevel Property .MyMap.ZoomLevel = 12;** valid values are between 1 to 20.
Set/Get the Directional Heading of the map
You can Set/Get the Directional heading of the map control with the Heading Property .MyMap.Heading = 360;** valid values are North =360 or 0,East =90 ,South =180,West =270 .
Set/Get the Tilt of the map
You can use the DesiredPitch Property to check if your map is tilted an angle or you can also tile you map to a desired angle by setting a valid value to this property .MyMap.DesiredPitch = 360;
** valid values are 0 to 65.
Update a new location in the map control
if you want to update the map with a new location you should use the MapControl.TrySetViewAsync method as shown belowawait MyMap.TrySetViewAsync(new Geopoint(new BasicGeoposition { Latitude = 50, Longitude = -5.399780 }));
**the method has three over loads using which you can set other parameters of the Map control like zoomlevel,heading,pitch and map animation kind when the new location value is set for the map.

0 comments:
Post a Comment