I seen tutorials about showing a map and other things but, I need the ability to input 2 address and it returns only the distance in miles to the location on a driving route.
Is this possible with app inventor?
I seen tutorials about showing a map and other things but, I need the ability to input 2 address and it returns only the distance in miles to the location on a driving route.
Is this possible with app inventor?
There are several ways to get the driving distance.
-This tutorial explains how to get the driving distance using App Inventor’s Navigate control HOW TO: Use the Navigate control This provides reasonable driving distance estimation (the basic data is provided by volunteers and is not always precisely accurate).
You can also use other methods
Use an ActivityStarter and intents to open Google’s Navigator app. This link provides basic information https://groups.google.com/forum/#!msg/mitappinventortest/3d7bFyGM508/pNsqAb9hBQAJ
This advice HOW TO use the new Map Control to plot a route on a map and post driving distance and time for that path. is useful too.
Again a different way is OpenStreetMap without the Map Component
And if you are experienced with JSON and willing to get a Google Map API, you can use the Google Directions API . This is the most accurate, up to date information provided from Google’s databases.
Is this what you want to do?
Regards,
Steve
/**
function GOOGLEMAPS(start_address,end_address,return_type) {
var mapObj = Maps.newDirectionFinder();
mapObj.setOrigin(start_address);
mapObj.setDestination(end_address);
mapObj.setMode(Maps.DirectionFinder.Mode.DRIVING);
var directions = mapObj.getDirections();
var getTheLeg = directions[“routes”][0][“legs”][0];
var meters = getTheLeg[“distance”][“value”];
Logger.log(directions);
switch(return_type){
case “miles”:
return meters * 0.000621371;
break;
case “minutes”:
// get duration in seconds
var duration = getTheLeg[“duration”][“value”];
//convert to minutes and return
return duration / 60;
break;
case “hours”:
// get duration in seconds
var duration = getTheLeg[“duration”][“value”];
//convert to hours and return
return duration / 60 / 60;
break;
case “kilometers”:
return meters / 1000;
break;
default:
return “Error: Wrong Unit Type”;
}
}
…
The code above is what I used to get this in Google Sheets. Then I made an app inventor app to place that data in the sheet and then retrieve the value to be displayed on the app.
My goal is to not need google sheets and do it purely from the app.
Everything you have linked doesn’t show me how to return only a variable. It’s a list or a lot of information I don’t need to have returned. The google API would work if I knew how to use it with App inventor.
almost everything linked to does show what is necessary to return only a value. So you don't need all the information returned; parse out what you want instead..
The google api returns a json file to your request; learn to use json with app inventor. All you need
is a Web component Google's development api credentials and the ability to parse json. Here is some help
and an example, easily adapted to App Inventor 2 using the Web Url and GetText Blocks to capture the json response
The following non App Inventor example requests the distance matrix data between Washington, DC and New York City, NY, retyrbs the result in JSON format:
Try it! You can test this by entering the URL into your web url block you construct (be sure to replace YOUR_API_KEY
with your actual API key). The response includes the distance and duration between the specified origins and destinations.
Create your url string using your two destinations using Text and Text join Blocks.
==============================================================
That is relatively straightforward. If you are lazy use the first method mentioned and do
which is a simplification of the Navigate tutorial. It took 10 minutes. Remember, you have to obtain a free api key described here> Maps and add both a Navigate and LocationSensor control (to geocode)
It results in the same distance as the tutorial (note the tutorial truncates rounds kilometers so it is not the same distance units used in the simple example. With the tutorial example, you get a free map :).
Here are some resources to help you learn to use the AI2 tools. A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFiles
How to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .
Also look here App inventor español. Offline. Tutorial. Ejemplos. Instalación. Códigos. Juegos. Curso gratis de App inventor. and here Tutorial Index | imagnity for more tutorials.
Regards,
Steve