2014년 12월 7일 일요일

Need Help Calculating Distance btw 2 Locations

I really need help or pointers , been stuck on this part for a while.

 I am trying  to  calculate the distance between my current location and  addresses in a list-
 and compare them to see which address is the closest -
then show my current location and which the address that is the closest



I have deleted your other post.  Please DO NOT DOUBLE POST ON THIS FORUM... WE see the posts, and if someone can answer you, they will.  Double posting is just a waste of space and time...

I'm sure someone will respond to your request as soon as possible.  Until then, please wait patiently.



A rough calculation is possible using the algorithm here  http://www.appinventor.org/Chapter21   .  This algorithm is not very accurate but is simple to use.   What it does is attempt to calculate the straight-line distance between two points.  A better algorithm is known as the Haversine algorithm.  If you search the Internet, you will see the mathematics that is required.   You will have to convert the equations to AI2 Math blocks.

Calculations of distance using shortest distance by road/highway can be made by using the Google Map API.  Read about the Google Distance Matrix here:   https://developers.google.com/maps/documentation/distancematrix/      How you use it with AI2 is complex but doable using JSON and the Web component.  There are restrictions on the use of this Google feature.   Use over certain limits requires payment to Google.   Additionally there are other requirements.


Use of the Distance Matrix API must relate to the display of information on a Google Map; for example, to determine origin-destination pairs that fall within a specific driving time from one another, before requesting and displaying those destinations on a map. Use of the service in an application that doesn't display a Google map is prohibited.

There are several MIT tutorials that touch on the subject of mapping using Google and using the LocationSensor...  have you done the tutorials?   They are here: http://appinventor.mit.edu/explore/ai2/tutorials3818.html?&page=2



in case you are using a fusiontable, you can sort easily using the ORDER BY clause, see also SQL Reference Documentation of the Fusion Tables API.

SELECT * FROM <tableid>
ORDER BY ST_DISTANCE(<location_column>, <coordinate>) 

to learn how to work with fusiontables, do the Pizza Party tutorial!


댓글 없음:

댓글 쓰기