I feel that Calculate Distance script has been shared before, because it looks strikingly similar to one that I use in my mobile app (and is WAY better written than I ever could have done), so thank you.
Recently I was tasked by my cousin to come up with a delivery system for his brewery since they can only serve carryout during COVID. I did this using LiveCode server (https://midwestcoastmedia.com/beta_ltd/delivery.html <https://midwestcoastmedia.com/beta_ltd/delivery.html>) with Google Maps (and Untappd) APIs. Your post made me realize that I can update my current basic mobileLocation usage from just the “you are this far away” model to a “here’s how to get here” system. So thanks EVERYONE on this refresher! Here is the relevant code if anyone else finds it of interest. I was using $_POST values from an HTML form but you could easily modify the origin and destination to a number of formats: ## https://developers.google.com/maps/documentation/directions/start put urlEncode("12365 N Dumont Way, Littleton, CO 80125, USA") into tOrigin // his brewery put "https://maps.googleapis.com/maps/api/directions/json?origin=" & tOrigin & "&destination=" into tAPIurl put urlEncode(tAddress1 & COMMA && tCity & COMMA && "CO" && tZip & COMMA && "USA") into tDestination put tDestination after tAPIurl put "&key=WHATEVERYOURAPIKEYISGOESHERE" after tAPIurl put url tAPIurl into tJSON —Andrew Bell > > Ralph, this is brilliant. I remember trying to do something similar years > ago, and giving up because I didn't know how to do the math. I suck at math, > or rather I am too lazy and impatient to work the problem. > > Bob S > >> On Apr 3, 2020, at 14:27 , Ralph DiMola via use-livecode >> <email@example.com> wrote: >> >> Graham, >> >> This my distance calculation for what it's worth. >> >> Function distance lat1, lon1, lat2, lon2, unit >> -- Calculate Distance between to points >> -- >> --lat1, lon1, lat2, lon2 are in deg.fractionalDegrees >> -- Unit >> -- if empty then miles >> -- K = kilometers >> -- N = nautical miles >> local theta >> local dist >> >> Put lon1 - lon2 into theta >> put Sin(deg2rad(lat1)) * Sin(deg2rad(lat2)) + Cos(deg2rad(lat1)) * >> Cos(deg2rad(lat2)) * Cos(deg2rad(theta)) into dist >> >> put Acos(dist) into dist >> put rad2deg(dist) into dist >> put dist * 60 * 1.1515 into dist >> >> switch unit >> case "K" >> put dist * 1.609344 into dist >> case "N" >> put dist * 0.8684 into dist >> end switch >> >> Return dist >> >> End distance >> >> >> Function rad2deg rad >> Return rad / PI * 180.0 >> end rad2deg >> >> >> Ralph DiMola >> IT Director >> Evergreen Information Services >> rdim...@evergreeninfo.net > > > _______________________________________________ use-livecode mailing list firstname.lastname@example.org Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode