Make DirectionsService.Route method return a DirectionsResult #108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there,
We are wanting to have
DirectionsService.Route
return aDirectionsResult
. We have been (and still do) useDirectionsRenderer.Route
to do this, but we wanted to be able to query the Api without displaying the results on the map.We investigated making HTTP calls directly to the Directions Api but Google blocks this (through CORS) when you are calling from a browser (as in Blazor WebAssembly) so the only option is the use the Javascript Api.
The original
DirectionsService.Route
returned aDirectionResponse
but on inspecting the code it was always null.To solve the issue we copied the code from the
DirectionsRenderer.Route
method. We also had to changeobjectManager.js
to ensure that thesetDirections
method was only called if it existed.setDirections
does exist inDirectionsRenderer
but not inDirectionsService
.We realise changing the return type of
DirectionsService.Route
to aDirectionResponse
is a breaking change but, without wanting to offend, the original code would always returnnull
anyway, so we don't believe this would be an issue for anyone using the library already.To test the result of this PR, replacing the code in
MapRoutes.razor.cs
in the demo with the following code will get the route result and update the duration and distance but not draw the route on the map.