Currently, you can launch the game on the phone and see locations of other players on the map and in the augmented reality. However, after clicking on the navigation button nothing happens. In this part, you will add another feature that allows running the navigation to the player after clicking on the Navigate button, both in the Map and World screens.
The navigation to the specific GPS coordinates is possible using the Maps directions task. In this section, you will use only a subset of its features, because you just need to find a route from your current location to the specified GPS coordinates. However, the player name should be shown instead of raw coordinates.
In previous chapters, you created the GameHelpers
static class. Here, you will add the NavigateToPlayer
method, which starts the navigation:
public static void NavigateToPlayer(string playerName,
GeoCoordinate location)
{
MapsDirectionsTask task = new MapsDirectionsTask();
LabeledMapLocation endPoint =
new LabeledMapLocation(playerName, location);
task.End = endPoint;
task.Show();
}
To launch the navigation, you create a new instance of the MapsDirectionsTask
class (from the Microsoft.Phone.Tasks
namespace), set the end point (both the name and location), and call the Show
method. The navigation mechanism starts automatically, as well as the route is calculated and presented to the user.
The view model classes for the Map and World screens contain the NavigateToPlayer
method. However, currently they do not contain any code. To support the navigation, you need to call the NavigateToPlayer
method (from the GameHelpers
class) with suitable parameters (the player name and location), as shown in the following code:
public void NavigateToPlayer(PlayerData player)
{
GameHelpers.NavigateToPlayer(player.Name, player.Location);
}
Let's launch the game and run navigation! After clicking on the Navigate button (on the Map or World screens) you should be automatically moved to the external application, which presents a route to the player, as shown in the following screenshot:
52.15.245.1