thanks for the advise, actually here is the code.
function print_r ( t )
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
print(indent…"*"…tostring(t))
else
print_r_cache[tostring(t)]=true
–if (type(t)==“table”) then
for pos,val in pairs(t) do
if (type(val)==“table”) then
print(indent…"["…pos…"] => “…tostring(t)…” {")
sub_print_r(val,indent…string.rep(" “,string.len(pos)+8))
print(indent…string.rep(” “,string.len(pos)+6)…”}")
else
print(indent…"["…pos…"] => “…tostring(val))
end
end
–else
–print(indent…tostring(t))
–end
end
end
sub_print_r(t,” ")
end
– Locals
local cos = math.cos
local sin = math.sin
local pi = math.pi
local sqrt = math.sqrt
local min = math.min
local asin = math.asin
local abs = math.abs
– Calculate distance
function 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
– Markers
local markers = {
{ title=‘sasa1’, latitude = 7.07220007, longitude = 125.6208795}, – will become position 3
{ title=‘sasa2’, latitude = 7.0723912, longitude = 125.61704414}, – will become position 1
{ title=‘sasa3’, latitude = 7.07362466, longitude = 125.61977253} – will become position 2
}
--currentLatitude = curentLocation.latitude
--currentLongitude = currentLocation.longitude
– Center; could be your current GPS location
centerPoint = {latitude = 7.07525189, longitude = 125.61961413} – new york
–centerPoint = {currentLocation}
–local centerPoint = {myMap:getUserLocation()}
– Set distances in markers
for i, Prop in ipairs(markers) do
Prop[‘distance’] = distance(centerPoint, markers[i])
end
– Sort by distance
function compare(a,b)
return a[‘distance’] < b[‘distance’]
end
table.sort(markers, compare)
– Print sorted markers
local newText =
"Nearest is: " print_r(markers[1])
native.showAlert( “You Are Here”, nearestText, { “OK” } )
end
as you can see the above code, the code is working, the output is properly showing in the corona simulator. The problem is that we want to use the output from the simulator to appear in our googlemap like showing what longlat is the output from the simulator.