Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with Directions API #531

Closed
TouqeerAhmad opened this issue Feb 8, 2018 · 41 comments
Closed

Help with Directions API #531

TouqeerAhmad opened this issue Feb 8, 2018 · 41 comments
Assignees
Labels

Comments

@TouqeerAhmad
Copy link

Hi, I am trying to find a demo/sample where I can use mapbox unity sdk and use directions api. I want exactly what is described in the following link but for unity. Any help in this regards will be great.

https://www.mapbox.com/help/getting-started-directions-api/

@wilhelmberg
Copy link
Contributor

@TouqeerAhmad
Copy link
Author

Thank you!
That just give a geojson file but not the route on the map. In iOS native, I was able to use Navigation SDK and get the route from geojson, but I want to do the same using mapbox unity sdk. Like something similar to store locator demo in iOS/android but for unity.

@wilhelmberg
Copy link
Contributor

@TouqeerAhmad this SDK doesn't create a route on the map for you out of the box.
You have to create the game object yourself based on the results of calling the directions API.
You can access the directions API via MapboxAccess.Directions.

@TouqeerAhmad
Copy link
Author

I understand, thanks!

@david-rhodes
Copy link

@TouqeerAhmad see GameObject ExampleDirectionsQuery in InteractiveStyledVectorMap.unity scene.

@TouqeerAhmad
Copy link
Author

@david-rhodes Thank you! that is somewhat relevant but not exactly what I was looking for.

@wilhelmberg
Copy link
Contributor

@TouqeerAhmad what exactly are you looking for?

Example mentioned by @david-rhodes shows how to visualize the response of the directions API:

image

And DirectionsFactory.cs that is used by the example scene shows how to work with the strongly typed DirectionsResponse that's returned by the query.

Sorry but we don't pass GeoJSON around in SDK.

@TouqeerAhmad
Copy link
Author

Yes, I understand that -- I am looking into that example and code file you guys have suggested. Thank you both! Is there a plan to release Navigation SDK for unity in future, as I feel that is more mature than Directions API but only available for native iOS/Android.

@TouqeerAhmad
Copy link
Author

TouqeerAhmad commented Feb 9, 2018

Hi Guys, using your suggested script along with LocationProvider, I am able to hard code start and end lat/long and the path gets high lighted in blue. The location of the user is specified by an anchor. Now, my objective is to get the device location from the location provider -- that gives me one of the lat/long -- the other one i.e. the destination shall be fixed and I want to give directions to the user to reach my asset/destination but using Unity.

I was wondering if that shall be possible using Directions API and if you can get me some more pointers.

Essentially want to replicate what is out there using Navigation SDK for iOS

https://github.com/mapbox/mapbox-navigation-ios

I can see some of the same things e.g. Waypoint etc. on both iOS side and Unity side.
img_0134

@david-rhodes
Copy link

Instead of using a transform (waypoint) that gets converted to GPS, just use a hardcoded lat/lon for your destination. The queries still operate the same.

@sahmilcheelan
Copy link

hello,i am a college student and I am working on a project "AR based navigation application for android using unity".since I am new to this field I don't have any idea where and how to start with.and after some research I got to know that mapbox sdk can help me out.and I need almost the same requirements as @TouqeerAhmad wants.like I want the user to enter the desired destination and the application should provide the path to the user as an augmented path on the real world scene captured through the users camera,and I need it in android.
so can anyone help me out?

thanks in advance :)

@TouqeerAhmad
Copy link
Author

TouqeerAhmad commented Feb 12, 2018

@david-rhodes yes already fixed the two location -- able to get the current location of the user and location I specified for my asset and getting the route highlighted as I shown in the above picture.

My next step is to get the turn by turn directions displayed to user and with voice as well -- not sure if that is something doable by Directions API -- may be a Navigation SDK for Unity should be there :)

@david-rhodes
Copy link

@TouqeerAhmad You can get maneuvers from the directions response. https://www.mapbox.com/api-documentation/#routestep-object also has lots of information pertinent to navigation. I'm sure the Unity asset store has text to voice assets ready for purchase: https://assetstore.unity.com/packages/tools/audio/rt-voice-48394.

@TouqeerAhmad
Copy link
Author

Cool, thanks for the continued help!

@vahidreza
Copy link

hey,
I have downloaded the latest mapbox unity sdk and I could not find a GameObject named ExampleDirectionsQuery in InteractiveStyledVectorMap.unity scene.
I think I have checked almost all scenes but maybe I missed something.

I want to simply draw path on the map based on given coordinates and I do not know how.

thanks

@richardzzzarnold
Copy link

richardzzzarnold commented Jun 13, 2018

TouqeerAhmad, any chance you could share your code for this? It seems like this is exactly what a lot people are wanting..

@abhishektrip
Copy link
Contributor

@TouqeerAhmad
Copy link
Author

@richardzzzarnold
Richard I have switched job and no longer have access to the code I wrote at that time.
Good luck!

@richardzzzarnold
Copy link

richardzzzarnold commented Jun 14, 2018 via email

@abhishektrip
Copy link
Contributor

@richardzzzarnold You need to trigger the [Query] (

) method when your end points move. Our example is setup to update the direction when map's location/zoom is changed. You will need to write logic to trigger the query when end points move.

@richardzzzarnold
Copy link

richardzzzarnold commented Jun 15, 2018 via email

@richardzzzarnold
Copy link

richardzzzarnold commented Jun 15, 2018 via email

@wilhelmberg
Copy link
Contributor

Would I be correct in thinking that in unity the scripting backend setting in the Player Settings would need to be selected as Mono instead of IL2CPP?

Yes @richardzzzarnold there currently seem to be some hiccups whenever JSON parsing (the directions response from the API) and IL2CPP are involved.

Please try again with Mono/.NET scripting backend.

@richardzzzarnold
Copy link

richardzzzarnold commented Jun 17, 2018 via email

@wilhelmberg
Copy link
Contributor

@richardzzzarnold you are right about IL2CPP and iOS, doesn't work any other way - I mixed that up with UWP/HoloLens where we have troubles with JSON and IL2CPP.

We just did a quick test and directions on iOS worked fined for us.

Could you share your query (start- and endpoint) so that we can check the API response.
Maybe some property is not populated and we are missing a null check.

@richardzzzarnold
Copy link

richardzzzarnold commented Jun 19, 2018 via email

@richardzzzarnold
Copy link

richardzzzarnold commented Jun 19, 2018 via email

@wilhelmberg
Copy link
Contributor

Maybe @atripathi-mb can chime in on 1.

@ 2.

... should I call PollLocationRoutine every second?

No, that should get polled automatically - unless it breaks out of that loop, eg in case Unity couldn't connect to the device's location service.
Check your device logs if you see any errors related to that.

You might want to take a look at the LocationProvider example in the Playground folder and check if that scene works on your device.

We've seen strange behavior regarding location updates on some devices with wifi on, try this:

  • switch off wifi
  • reboot the device
  • keep wifi off and try again

Also map setup has to be changed when you want continuous updates:

  • uncheck Initialize On Start under GENERAL in Abstract Map
  • add Initialize Map With Location Provider script to your map
  • add Update Map With Location Provider script to your map

Lastly, could you share your LocationProviderFactory and DeviceLocationProvider settings?
Eg Unity won't give you location updates if there's a high value in Desired Accuracy even when you have a low value in Update Distance.

@richardzzzarnold
Copy link

richardzzzarnold commented Jun 21, 2018 via email

@richardzzzarnold
Copy link

richardzzzarnold commented Jun 21, 2018 via email

@wilhelmberg
Copy link
Contributor

Also as mentioned before in 1) the directional waypoint entity does not flow with the zoom and pan.

Sorry, I cannot help with that but I already pinged a colleague above.
He's at a conference this week so will probably get back to you next week.

Also, I should add , that if the app needs to go through these steps in order to function properly, it may not be suitable for this app.
I don’t think I will be able to persuade my customers to do this every time they leave their house.

Of course not, we don't want to do that either.
I just shared some information we found out the hard way ourselves to save you some trouble and to easily rule out a problem that we've seen pop up intermittently with some Unity versions and some devices.
That's why we even implemented a native Android location plugin: to work around the inconsistent behavior of some 2017.x versions.

I imagine Mapbox probably prefers Native development.

Please feel free to take a look at our other SDKs:
https://www.mapbox.com/developers/
https://www.mapbox.com/augmented-reality/

@abhishektrip
Copy link
Contributor

@richardzzzarnold

The zooming function as demonstrated in the ZoomableMap scene does not seem to affect a direction waypoint entity.

Map and the directions are different entities. Directions response is a set of locations, our example uses the line renderer to draw them for demonstration purpose. You will have to re-draw the direction lines when the map updates, I would suggest using the OnMapUpdated event to trigger your direction line redraw.

@EarthAdam
Copy link

I have a problem that seems fitting for this thread: In the WorldScale AR scene I am able to get the directions route "direction waypoint entity" to show up in Play mode, but when I build it into an SDK it doesn't show up. Any suggestions?

@FFilippidis
Copy link

@atripathi-mb

we are in the process of creating a new example dedicated to directions

Any update on this by any chance?
Thanks

@abhishektrip
Copy link
Contributor

@FFilippidis Directions example is available in the latest release v1.4.4

@FFilippidis
Copy link

Hi @atripathi-mb

Thanks for the fast reply and help.
Is there an example that shows how to visualise the response of the directions API?

@EarthAdam
Copy link

@atripathi-mb I tried the new version. The new traffic rendering looks really cool, but the same problems exist in getting the Directions API to show up in WorldScale AR mode on the phone. All of the other map layers I choose to show will show up, just not the Directions route. Do you know who could help with this?

@abhishektrip
Copy link
Contributor

@OhioAdam Could you give me steps to recreate the issue or point me to a sample project/code to help you out. I can't think of any reason why directions will not show up when built on device.

@abhishektrip
Copy link
Contributor

@FFilippidis The traffic and Directions example is visualizing the Directions API response. Are you looking for something else?

@EarthAdam
Copy link

I'm looking to get the Directions response to show up in AR. I open up the WorldScaleAR Scene, toggle on the Directions GameObject under ArAlignedMap, and get it to the point of showing a directions route from the player's perspective during "Play" mode (it shows up as a GameObject called "directions waypoint entity"). When I build that scene into an APK and load it on a phone, the building geometries show up, but the "directions waypoint entity" is nowhere to be seen.

@FFilippidis
Copy link

@atripathi-mb Yes it is visualising the responce but i was wondering if there was an example file similar to the earlier one in the InteractiveStyledVectorMap.unity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants