distance find in location ?

I Have to find distance from old location  to new location

as in ios  :

// returns distance in meters

        distance+=[newLocation distanceFromLocation:oldLocation] ;

        float Dis =distance*0.00062137119;

 

but i have to work down in corona…

between 2 GPS points ?

You’ll want to use the Haversine Formula for this.  It’s not super accurate, but over short distances it is close enough.

local mDeg = math.deg local mRad = math.rad local mCos = math.cos local mSin = math.sin local mAcos = math.acos local mAsin = math.asin local mSqrt = math.sqrt local mCeil = math.ceil local mFloor = math.floor local mAtan2 = math.atan2 local mPi = math.pi -- Calculate the distance from one decimal lat-long position to another. -- Distance is a multiple of R (either kilometers or miles) -- More accurate for short distances than long. function math.haversine\_dist( lat1, lng1, lat2, lng2, R ) --[[haversine formula dlon = lon2 - lon1 dlat = lat2 - lat1 a = (sin(dlat/2))^2 + cos(lat1) \* cos(lat2) \* (sin(dlon/2))^2 c = 2 \* atan2( sqrt(a), sqrt(1-a) ) d = R \* c (where R is the radius of the Earth; radius of the Earth: 3961 miles and 6373 km) --]] local R = R or 6373 -- Default radius of earth in km local dlng = mRad(lng2 - lng1) local dlat = mRad(lat2 - lat1) local lat1 = mRad(lat1) local lat2 = mRad(lat2) local a = (mSin(dlat/2))^2 + mCos(lat1) \* mCos(lat2) \* (mSin(dlng/2))^2 local c = 2 \* mAtan2( mSqrt(a), mSqrt(1-a) ) local d = R \* c --(where R is the radius of the Earth) return d end

I have to use but Attempt to call global ‘haversine_dist’ (a nil value)

function math.haversine_dist( lat1, lng1, lat2, lng2, R )

local R = R or 6373 – Default radius of earth in 6373 km

local dlng = mRad(lng2 - lng1)

local dlat = mRad(lat2 - lat1)

local lat1 = mRad(lat1)

local lat2 = mRad(lat2)

local a = (mSin(dlat/2))^2 + mCos(lat1) * mCos(lat2) * (mSin(dlng/2))^2 

local c = 2 * mAtan2( mSqrt(a), mSqrt(1-a) ) 

local d = R * c --(where R is the radius of the Earth)

return d

end 

 print(haversine_dist( 22.023, 23.023, 25636.2, 598.56))

Call it from the math library.

That snippet you copied from was a note, not exact code to be used.

Call like this:

 print( math.haversine\_dist( 22.023, 23.023, 25636.2, 598.56) )

@roaminggamer

Thanks it’s do good working.

some help me more .

can i have to add overlay on mapview?

if yes, how do it.

i have to draw line on mapView ?

myMap:addMarker( event.latitude, event.longitude)

this is only indicate the point but i wants to replace this point to on line.

Sorry, can’t help you with that.

This is not possible with the current map view

between 2 GPS points ?

You’ll want to use the Haversine Formula for this.  It’s not super accurate, but over short distances it is close enough.

local mDeg = math.deg local mRad = math.rad local mCos = math.cos local mSin = math.sin local mAcos = math.acos local mAsin = math.asin local mSqrt = math.sqrt local mCeil = math.ceil local mFloor = math.floor local mAtan2 = math.atan2 local mPi = math.pi -- Calculate the distance from one decimal lat-long position to another. -- Distance is a multiple of R (either kilometers or miles) -- More accurate for short distances than long. function math.haversine\_dist( lat1, lng1, lat2, lng2, R ) --[[haversine formula dlon = lon2 - lon1 dlat = lat2 - lat1 a = (sin(dlat/2))^2 + cos(lat1) \* cos(lat2) \* (sin(dlon/2))^2 c = 2 \* atan2( sqrt(a), sqrt(1-a) ) d = R \* c (where R is the radius of the Earth; radius of the Earth: 3961 miles and 6373 km) --]] local R = R or 6373 -- Default radius of earth in km local dlng = mRad(lng2 - lng1) local dlat = mRad(lat2 - lat1) local lat1 = mRad(lat1) local lat2 = mRad(lat2) local a = (mSin(dlat/2))^2 + mCos(lat1) \* mCos(lat2) \* (mSin(dlng/2))^2 local c = 2 \* mAtan2( mSqrt(a), mSqrt(1-a) ) local d = R \* c --(where R is the radius of the Earth) return d end

I have to use but Attempt to call global ‘haversine_dist’ (a nil value)

function math.haversine_dist( lat1, lng1, lat2, lng2, R )

local R = R or 6373 – Default radius of earth in 6373 km

local dlng = mRad(lng2 - lng1)

local dlat = mRad(lat2 - lat1)

local lat1 = mRad(lat1)

local lat2 = mRad(lat2)

local a = (mSin(dlat/2))^2 + mCos(lat1) * mCos(lat2) * (mSin(dlng/2))^2 

local c = 2 * mAtan2( mSqrt(a), mSqrt(1-a) ) 

local d = R * c --(where R is the radius of the Earth)

return d

end 

 print(haversine_dist( 22.023, 23.023, 25636.2, 598.56))

Call it from the math library.

That snippet you copied from was a note, not exact code to be used.

Call like this:

 print( math.haversine\_dist( 22.023, 23.023, 25636.2, 598.56) )

@roaminggamer

Thanks it’s do good working.

some help me more .

can i have to add overlay on mapview?

if yes, how do it.

i have to draw line on mapView ?

myMap:addMarker( event.latitude, event.longitude)

this is only indicate the point but i wants to replace this point to on line.

Sorry, can’t help you with that.

This is not possible with the current map view