Topic: How can I use OnlineMapsFindDirection -> waypoint
Hi,
I recently I want to draw the line with route, in addition, I want to set the waypoint (via root).
But I don't know how to use it
can you help me?
You are not logged in. Please login or register.
Infinity Code Forum → Online Maps Help → How can I use OnlineMapsFindDirection -> waypoint
Hi,
I recently I want to draw the line with route, in addition, I want to set the waypoint (via root).
But I don't know how to use it
can you help me?
Hello.
Waypoints can be an array or a list, where the values is string or Vector2.
Example:
string[] waypoints = {"Waypoint 1", "Waypoint 2", "Waypoint 3"};
List<Vector2> waypoints2 = new List<Vector2>
{
new Vector2(lng1, lat1),
new Vector2(lng2, lat2),
new Vector2(lng3, lat3),
};
OnlineMapsGoogleDirections query = OnlineMapsGoogleDirections.Find(new OnlineMapsGoogleDirections.Params(origin, destination)
{
waypoints = waypoints
});
An example of how to draw a route:
http://infinity-code.com/atlas/online-m … ample.html
Hi
I'm testing the same, but with no sucess, it always gives me Zero results....
public float placeLatitude2GO, placeLongitude2GO;
float placeLatitude1, placeLongitude1;
string[] waypoints = { "Waypoint 1", "Waypoint 2", "Waypoint 3" };
List<Vector2> waypoints2 = new List<Vector2>
{
new Vector2(-7.911771f,38.555735f),
new Vector2(-7.916875f,38.562577f),
new Vector2(-7.902130f,38.565808f),
};
public void MakeFeaturedRoutes()
{
//Remove todas as linhas que tinha antes para criar a nova route
OnlineMaps.instance.RemoveAllDrawingElements();
if (OnlineMapsLocationService.instance.IsLocationServiceRunning())
{
placeLatitude1 = OnlineMapsLocationService.instance.position.y;
placeLongitude1 = OnlineMapsLocationService.instance.position.x;
Debug.Log("[MakeFeaturedRoute.cs] Latitude: " + placeLatitude1 + " e Longitude: " + placeLongitude1);
OnlineMapsGoogleDirections query = OnlineMapsGoogleDirections.Find(new OnlineMapsGoogleDirections.Params(new Vector2(placeLongitude1, placeLatitude1), new Vector2(placeLongitude2GO, placeLatitude2GO))
{
//mode = OnlineMapsGoogleDirections.Mode.walking, //Mode de ir a pé
waypoints = waypoints
});
// Specifies that search results must be sent to OnFindDirectionComplete.
query.OnComplete += OnFindDirectionComplete;
}
}
private void OnFindDirectionComplete(string response)
{
// Get the resut object.
OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);
// Check that the result is not null, and the number of routes is not zero.
if (result == null || result.routes.Length == 0)
{
Debug.Log("Find direction failed");
Debug.Log(response);
return;
}
// Showing the console instructions for each step.
foreach (OnlineMapsGoogleDirectionsResult.Leg leg in result.routes[0].legs)
{
foreach (OnlineMapsGoogleDirectionsResult.Step step in leg.steps)
{
Debug.Log(step.string_instructions);
}
}
// Create a line, on the basis of points of the route.
OnlineMapsDrawingLine route = new OnlineMapsDrawingLine(result.routes[0].overview_polyline, Color.green);
// Draw the line route on the map.
OnlineMaps.instance.AddDrawingElement(route);
}
debugs "Find Direction failed"
and the xml:
<?xml version="1.0" encoding="UTF-8"?>
<DirectionsResponse>
<status>ZERO_RESULTS</status>
</DirectionsResponse>
This means Google Directions API can not find this route.
First of all, try to find a route without waypoints.
If this works without waypoints, show me the coordinates that you use in placeLatitude2GO and placeLongitude2GO. I will check it.
Thanks for the reply, and your availability!
The coordinates for placeLatitude2GO and placeLongitude2GO are : 38.56486, -7.920602
I can generate a valid route between user location and final location. But when I add waypoints as you suggested in the code, the API gives zero results.
This is because you pass an array of dummy strings to waypoints.
In your case, you need to pass waypoints2.
In the example in post 2, I meant that you can pass an array or a list that contains the names of the locations (address) or coordinates.
This is because you pass an array of dummy strings to waypoints.
In your case, you need to pass waypoints2.In the example in post 2, I meant that you can pass an array or a list that contains the names of the locations (address) or coordinates.
Yes that's it!
Sorry for not paying attetion to that detail!
One more problem
In the code I wrote. i want placeLatitude2GO and placeLongitude2GO to disapear and make the last waypoint given. The last waypoint should be where the route ended. But with this code it adds one more route to placeLatitude2GO and placeLongitude2GO.
How can i solve this?
Just delete the last point from the waypoints.
Infinity Code Forum → Online Maps Help → How can I use OnlineMapsFindDirection -> waypoint
Powered by PunBB, supported by Informer Technologies, Inc.