Topic: Online Maps only draws the line for route in app, not Unity Editor
I have got my Google API key working and I can now from the Atlas examples get Autocomplete queries back successfully and also get routes return from:
https://infinity-code.com/atlas/online- … ample.html
I can enter two addresses as strings, and the returned data is correct in terms of distance and expected duration of transit. So I know the query is going and coming back okay.
However, it is not drawing the red line on the map for the route between the two locations in Unity Editor. It does seem to draw it in the real Android app. Is there any obvious reason this would be the case?
I am running a script on my Maps object with:
Start(){
FindRouteRequest("Street Address 1, City", "Street Address 2, City");
}
private void FindRouteRequest(Vector2 source, string destination) {
// Find route using Google Directions API
OnlineMapsGoogleDirections request = new OnlineMapsGoogleDirections(googleAPIKey, source, destination);
request.OnComplete += OnGoogleDirectionsComplete;
request.Send();
}
private void OnGoogleDirectionsComplete(string response) {
Debug.Log(response);
// Try load result
OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);
if (result == null || result.routes.Length == 0) return;
// Get the first route
OnlineMapsGoogleDirectionsResult.Route route = result.routes[0];
// Draw route on the map
OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingLine(route.overview_polyline, Color.red, 5));
//zoom to fit route
// Calculate the distance
int distance = route.legs.Sum(l => l.distance.value); // meters
// Calculate the duration
int duration = route.legs.Sum(l => l.duration.value); // seconds
// Log distane and duration
Debug.Log("Distance: " + distance + " meters, or " + (distance / 1000f).ToString("F2") + " km");
Debug.Log("Duration: " + duration + " sec, or " + (duration / 60f).ToString("F1") + " min, or " + (duration / 3600f).ToString("F1") + " hours");
}As said, all the Debug output seems 100% correct so it seems to be working, and it does draw the route in Android app, just not in Unity Editor.
Is there any good reason this would be the case?
Is there something else I need to do to see the line in Unity Editor?
Also, is there any good way to get the map to zoom to the size of the line? Ie. To fit the route to screen?
Thanks.