Yes I do have a stable Wifi connection. I used all of your tutorial blocks and added other things. The thing is the linestring is not really functioning and I am not sure how to code a distance calculation button.
aia removed
Hmm. I'll have a look at your aia in a while. In the meanwhile here
is something to try
navigateBetweenCoordinates_4.aia (5.0 KB)
Before using the aia, replace YOUR api key in the appropriate Screen1.Initialize Block. Does the example do what you want it to do?
How do I use your aia in MIT app inventor?
- connect your PC to the internet ]
- load the aia into App Inventor Project>Import project (aia) from the computer
- go to the Blocks screen and add your api token in the Block in the Screen1.Initialize
- run the app using Companion
- the first time you use the app, you might just leave the origin/destination as it is shown on the screen (the default data) just to see how it works. Simply press the Find Route between button and the app will use the coordinates shown.
- if you want to just use your own origin and destination route; the origin latitude and longitude textboxes are used to set the origin point. Type the latitude as decimal degrees (example 3.19 ) Fill in the destination latitude and longitude.
- Press the Find Route between to have the app display the route.
Origin/Destination input is done using the four textboxes. You can use any other method you can code instead to set the Origin and Destination by modifying the code.
You could eventually code the app to use the LocationSensor to post the Origin latitude longitude in the text boxes and make a List of latitude/longitude pairs to fill in the Destination using a ListView to show, select and send the coordinates to the Destination textboxes. This would be your app to show the route between 2 locations and have a button calculate the distance of travelling the route.
- Distance and route estimated travel time using a car is posted above the map.
- Origin marker is green, destination marker is red.
- Turn by turn navigation instructions for driving the route are shown below the map.
now works mostly. You MUST use decimal latitude and longitude coordinates. For security reasons I removed your ors api code. To run you will need to reenter the api token using the Navigate properties APIKey box.
final_one_ revised.aia (7.5 KB)
This aia's linestring does not function as to what I want. The linestring is meant to connect the two markers and when I click "find route" the route(linestring) should follow wherever the two markers went and create a route.
And also I still want to know what components and blocks to use to program a distance calculation button following the route.
Could you send an aia regarding these two requests?
At this time I cannot. It is not clear to me what you are requesting in each instance.
The navigateBetweenCoordinates_4.aia shows you how to create a route between two Markers (one at the start of travel; the other marker at the Destination). It does that and posts the markers and linestring on the map..
I do not understand what you mean by "route(linestring) should follow wherever the two markers went and create a route." Press the button and the app requests a route from the ors server from the origin point to the destination and posts the route and two Markers on the map.
If you want the behavior to be different you have to code the app to do whatever you want it to do. Unfortunately I don't know what you expect to happen. Perhaps you want to show directions to different coordinates using a ListViewer. What the aia shows is for a single set of coordinates.
The code is in the same aia. When you use Button1.Button4 calls the call call RequestDirections Procedure. The RequestDirections procedure directs the app to query the ors server; when it connects it captures the response in the Navigation1.GotDirection block for directions, points, distance and duration which are ALL calculated by ors.
The calculated distance is set to the global totalDistance (so it can be used in other parts of the app if required) and the units posted in a Label after converting the meter units to kilometers.. You cannot directly use a Button to capture the distance. other than using the GotDirection block.
See the documentation at Maps
If you must, use a Button to post the calculated distance by setting a Label to totalDistance. That will display you the distance in meters that has already been calculated by ors Event.GotDirections and posted in Label4.
This example also posts the estimated driving time where the distance and duration produced by GotDirections is = totalDistance and tripDuration
how do i display the distance?
Answered several times. I do it using the example in #30 or something similar using a label after I have done a RequestDirection
What have YOU tried?
Yes this is what i need. Is the coding done in your final aia or is there another coding for this?
-
The navigateBetweenCoordinates_4.aia creates a route between two Markers (one at the start of travel; the other marker at the Destination). It does that and posts the markers and linestring on the map. You have had that file for six days and it appears you never tested it.
-
Copy your api key into the Navigation1.APIKey block in the Screen1.Initialize replacing the words '** YOUR ors api key goes here **' .
-
Load the aia using Companion to test using default coordinates already entered
-
When you run the app, don't change anything yet.
-
Press the Find Route between Button
-
wait for the route posted between the Origin and Destination default coordinates
If the route posts, be happy.
If it does not produce a route, sorry I can't provide any other help. A route should have been provided.
If you want the behavior to be different, code the app to do whatever you want it to do. Unfortunately I don't know what else you expect to happen.
[
Good luck.
It doesn't work. I tested it. But anwyays thanks for your help.
It doesn't display the distance though.
Yes it does display the distance.
What happens instead of working when you test. Do you see an error message?
This works fine on my Android 13.
I am using ios so I am not so sure.I don't see an error message. It just basically shows nothing.
We just had a similar issue with others where Navigate works on Androids but NOT on ios. MIT will look at that and hopefully fix the problem soon.
MIT indicates Navigate should be fixed in the version available on TestFlight.
MIT App Inventor for iOS Version 2.64.6 in TestFlight App Inventor for iOS . You could test the distance and route aia using the advice in the link above or wait for for the problem to get fixed on the main ios server with a future update, hopefully soon.
Try using the TestFlight Server using the Navigate aia while waiting for MIT to release an updated ios Companion. Let us know if using the TestFlight version works for you.