Fdumaine
2009-11-18 01:19:02 UTC
Hi!
I need help. I try the code you can find after. But i have a message :
There is no route data available in the region of the world where the
destination is located.
Can you help me ? What i need to do ? I just want Calculate the route
between 2 positions.
Thank you
François
protected void Button1_Click(object sender, EventArgs e)
{
string key =
"Al2zEjOSE-qv7a2tD28S-FTytSusB46kxyiRnPX2FvgaXGhhgYLCl7manpjCtrA6";
try
{
// Get a token before making a request
//string token = GetToken();
RouteRequest routeRequest = new RouteRequest();
// Set the credentials using a valid Bing Maps token
routeRequest.Credentials = new Credentials();
routeRequest.Credentials.Token = GetToken(); //.ApplicationId =
key;
// Set the start, stop, and end points
Waypoint[] waypoints = new Waypoint[2];
waypoints[0] = new Waypoint();
waypoints[0].Description = "Start";
waypoints[0].Location = new Location();
waypoints[0].Location.Latitude = 45.619449;
waypoints[0].Location.Longitude = -72.958338;
waypoints[1] = new Waypoint();
waypoints[1].Description = "End";
waypoints[1].Location = new Location();
waypoints[1].Location.Latitude = 44.142104;
waypoints[1].Location.Longitude = -73.749724;
routeRequest.Waypoints = waypoints;
// Make the calculate route request
RouteService routeService = new RouteService();
RouteResponse routeResponse =
routeService.CalculateRoute(routeRequest);
// Iterate through each itinerary item to get the route directions
RouteLeg leg;
string directions = "";
for (int k = 0; k < routeResponse.Result.Legs.Length; k++)
{
leg = routeResponse.Result.Legs[k];
for (int i = 0; i < leg.Itinerary.Length; i++)
{
directions = directions + leg.Itinerary[i].Text + "<br>";
}
}
Response.Write(directions);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
private string GetToken()
{
// Set Bing Maps Developer Account credentials to access the Token
Service
TokenService.CommonService commonService = new
TokenService.CommonService();
commonService.Credentials = new
System.Net.NetworkCredential("148828", "Bonjour01!");
// Set the token specification properties
TokenService.TokenSpecification tokenSpec = new
TokenService.TokenSpecification();
tokenSpec.ClientIPAddress = "74.125.47.104";
tokenSpec.TokenValidityDurationMinutes = 60;
string token = "";
// Get a token
try
{
token = commonService.GetClientToken(tokenSpec);
}
catch (Exception ex)
{
throw ex;
}
return token;
}
I need help. I try the code you can find after. But i have a message :
There is no route data available in the region of the world where the
destination is located.
Can you help me ? What i need to do ? I just want Calculate the route
between 2 positions.
Thank you
François
protected void Button1_Click(object sender, EventArgs e)
{
string key =
"Al2zEjOSE-qv7a2tD28S-FTytSusB46kxyiRnPX2FvgaXGhhgYLCl7manpjCtrA6";
try
{
// Get a token before making a request
//string token = GetToken();
RouteRequest routeRequest = new RouteRequest();
// Set the credentials using a valid Bing Maps token
routeRequest.Credentials = new Credentials();
routeRequest.Credentials.Token = GetToken(); //.ApplicationId =
key;
// Set the start, stop, and end points
Waypoint[] waypoints = new Waypoint[2];
waypoints[0] = new Waypoint();
waypoints[0].Description = "Start";
waypoints[0].Location = new Location();
waypoints[0].Location.Latitude = 45.619449;
waypoints[0].Location.Longitude = -72.958338;
waypoints[1] = new Waypoint();
waypoints[1].Description = "End";
waypoints[1].Location = new Location();
waypoints[1].Location.Latitude = 44.142104;
waypoints[1].Location.Longitude = -73.749724;
routeRequest.Waypoints = waypoints;
// Make the calculate route request
RouteService routeService = new RouteService();
RouteResponse routeResponse =
routeService.CalculateRoute(routeRequest);
// Iterate through each itinerary item to get the route directions
RouteLeg leg;
string directions = "";
for (int k = 0; k < routeResponse.Result.Legs.Length; k++)
{
leg = routeResponse.Result.Legs[k];
for (int i = 0; i < leg.Itinerary.Length; i++)
{
directions = directions + leg.Itinerary[i].Text + "<br>";
}
}
Response.Write(directions);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
private string GetToken()
{
// Set Bing Maps Developer Account credentials to access the Token
Service
TokenService.CommonService commonService = new
TokenService.CommonService();
commonService.Credentials = new
System.Net.NetworkCredential("148828", "Bonjour01!");
// Set the token specification properties
TokenService.TokenSpecification tokenSpec = new
TokenService.TokenSpecification();
tokenSpec.ClientIPAddress = "74.125.47.104";
tokenSpec.TokenValidityDurationMinutes = 60;
string token = "";
// Get a token
try
{
token = commonService.GetClientToken(tokenSpec);
}
catch (Exception ex)
{
throw ex;
}
return token;
}