Skip to first unread message

Cfrangos

unread,
Apr 3, 2017, 12:50:01 AM4/3/17
to MIT App Inventor Forum
Hi,

I am creating an app where I would like to know the number of miles between to addresses in Google Maps. What is the best way for me to do this? How can I use Google Maps without the user even seeing the program being run?

Thx,
Cfrangos

SteveJG

unread,
Apr 3, 2017, 9:16:29 AM4/3/17
to MIT App Inventor Forum
How to calculate the distance between two points is described here:  https://groups.google.com/forum/#!searchin/mitappinventortest/distance$20between%7Csort:date  

You cannot calculate the distance directly using math and the street address.  The street address needs to be converted to geocoordinates (latitude and longitude).  If you know the geocoordinates of two points, the following will work to calculate MILES:


or you can use the Haversine method   




Both of these calculate straight-line distance...not the distance using streets or roads.

This code snippet will use Google Maps to calculate a route and indirectly provide a distance 

It will not be useful to you because it exposes Google Maps.  Using Google Maps API is one of the only ways you have available to provide  street distance  distances.  Google provides a Business Map API which is not free but has methods of providing distances and 'route directions'.  https://developers.google.com/maps/documentation/directions/intro      The results are displayed in JSON.

You asked:  How can I use Google Maps without the user even seeing the program being run?  -- you cannot without providing Google credit legally  I am aware of no simple way of doing this legally other than calculation of a straight line distance..  



What have you tried so far?   Posting some blocks would be helpful to the Forum.

We want you to have fun with App Inventor so 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  .

Does this help you program?    Please continue to ask questions here however if you read the information above, you will not have to wait for answers.

Just try some blocks and have fun.

Regards,
Steve

Reply all
Reply to author
Forward
0 new messages