2016-04-07 3 views
1

Я работаю с программой определения местоположения, используя Corona SDK. У меня есть значение изображения и изображения (Lat - Long). Используя код ниже, найдите XY-пиксели. Но прослушиватель мест не работает должным образом. В приемнике местоположения android запускается после первого выполнения. У меня есть точное значение лат-лона каждые 1 метр.Location listener Corona sdk

local function GetPixelCoordinatesInBounds(width,height,lat,lon) 

    minLat = 12.9837 
    maxLat = 12.9850 
    MAP_HEIGHT = W 
    minLon = 80.24662 
    maxLon = 80.24666 
    MAP_WIDTH = H-35 

    x = ((lon - minLon)/(maxLon - minLon)) * (MAP_WIDTH - 1) 
    y = ((lat - minLat)/(maxLat - minLat)) * (MAP_HEIGHT - 1) 
end 

local function locationHandler(event) 
if (event.errorCode) then 
     native.showAlert("GPS Location Error", event.errorMessage, {"OK"}) 

else 
    GetPixelCoordinatesInBounds(ImageWidth, ImageHeight, event.latitude, event.longitude) 
end 
    Runtime:addEventListener("location", locationHandler) 
+0

Может вам добавить более подробную информацию? то есть слушателя. – JLONG

+0

Итак, когда вы имеете в виду, что слушатель не работает, это не точно? или сама функция gps не работает? – JLONG

+0

Я не получаю точное значение. В том же месте я получаю значение diff. – AndroidUser

ответ

2

Я не думаю, что вы правильно обрабатываете координаты. Посмотрите на этот пример, где преобразуются координаты и приложение работает нормально:

function locationHandler(event) 
     -- Check for error (user may have turned off Location Services) 
    if event.errorCode then 
     title = display.newText("errorgps", 200, 150, "Verdana-Bold", 20) 
     --print("Location error: " .. tostring(event.errorMessage)) 
    else 

     ycor = string.format('%.6f', event.latitude) 
     xcor = string.format('%.6f', event.longitude) 
     accuracyText = string.format('%.3f', event.accuracy) 
    end 

mxl0 = 5 
myl0 = 4 
-- Specifically check here how you have to manipulate your local y coordinates 
     mxl = ((mxl0-xmin)/(xmax-xmin))*300+10 
     myl = -((myl0-ymin)/(ymax-ymin))*300+460 
      if mylocationi == 1 then mxl = ((mxl-zx[1])/(zx[2]-zx[1]))*300 end 
     if mylocationi == 1 then myl = ((myl-(zy[1]+zy[2])/2)/(zx[2]-zx[1]))*300+160 end 
    if mxl > 340 then mxl = 340 end 
    if myl > 460 then myl = 460 end 
    if mxl < 0 then mxl = 5 end 
    if myl < 160 then myl = 160 end 


    mylocation = display.newCircle(mxl, myl, 3) 
    mylocation:setFillColor(0,0,1) 
    timer.performWithDelay(1000, removecircle) 

end 
Runtime:addEventListener("location", locationHandler) 

Проверить это приложение, если это то, что вы пытаетесь сделать, я могу дать вам коды: https://play.google.com/store/apps/details?id=com.jorc.amirfarazmand.GPS&hl=en