Calculate the distance between your current GPS Location from the nearest marker of your mapview

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

I took the code from this post:

http://forums.coronalabs.com/topic/37827-calculate-distance-between-points-sort-them-works/

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

I took the code from this post:

http://forums.coronalabs.com/topic/37827-calculate-distance-between-points-sort-them-works/