Good day everyone,
I am new to corona sdk and i am developing an application that has a mapview and working on having a feature that could calculate the distance of the nearest marker from my current location. The program will output “only” the distance of my current location and my distance from the nearest marker. Your replies will be highly appreciated. Thank you.
Hi,
I’m working with Google Maps and needed a function that calculated which path was the shortest:
-- Calculate distance function util:distance(from, to) local distance = 0 local radius = 6367000 local radian = pi / 180 local deltaLatitude = sin(radian \* (from.latitude - to.latitude) /2) local deltaLongitude = sin(radian \* (from.longitude - to.longitude) / 2) local circleDistance = 2 \* asin(min(1, sqrt(deltaLatitude \* deltaLatitude + cos(radian \* from.latitude) \* cos(radian \* to.latitude) \* deltaLongitude \* deltaLongitude))) distance = abs(radius \* circleDistance) return distance end
Best regards,
Tomas
Hi,
I’m working with Google Maps and needed a function that calculated which path was the shortest:
-- Calculate distance function util:distance(from, to) local distance = 0 local radius = 6367000 local radian = pi / 180 local deltaLatitude = sin(radian \* (from.latitude - to.latitude) /2) local deltaLongitude = sin(radian \* (from.longitude - to.longitude) / 2) local circleDistance = 2 \* asin(min(1, sqrt(deltaLatitude \* deltaLatitude + cos(radian \* from.latitude) \* cos(radian \* to.latitude) \* deltaLongitude \* deltaLongitude))) distance = abs(radius \* circleDistance) return distance end
Best regards,
Tomas