Total Pageviews

Saturday, May 24, 2014

Event Location in detail (2)

event.speed
សំរាប់ instantaneous speed របស់ GPS device នៅក្នុង meters per second វានឹងចែកជាលទ្ធផល 0.447 ក្នុងការដាក់ជា Miler Per Hour
សូមមើលកូដះ
local locationHandler = function( event )
    -- Check for error (user may have turned off Location Services)
    if event.errorCode then
        native.showAlert( "GPS Location Error", event.errorMessage, {"OK"} )
        print( "Location error: " .. tostring( event.errorMessage ) )
    else
        local latitudeText = string.format( '%.4f', event.latitude )
        currentLatitude = latitudeText
        latitude:setText( latitudeText )

        local longitudeText = string.format( '%.4f', event.longitude )
        currentLongitude = longitudeText
        longitude:setText( longitudeText )

        local altitudeText = string.format( '%.3f', event.altitude )
        altitude:setText( altitudeText )

        local accuracyText = string.format( '%.3f', event.accuracy )
        accuracy:setText( accuracyText )

        local speedText = string.format( '%.3f', event.speed )
        speed:setText( speedText )

        local directionText = string.format( '%.3f', event.direction )
        direction:setText( directionText )

        -- Note: event.time is a Unix-style timestamp, expressed in seconds since Jan. 11970
        local timeText = string.format( '%.0f', event.time )
        time:setText( timeText )
    end
end

-- Activate location listener
Runtime:addEventListener( "location", locationHandler )

event.latitude
វាជា Latitude in degrees របស់ current GPS location
សូមមើលកូដះ
local locationHandler = function( event )
    -- Check for error (user may have turned off Location Services)
    if event.errorCode then
        native.showAlert( "GPS Location Error", event.errorMessage, {"OK"} )
        print( "Location error: " .. tostring( event.errorMessage ) )
    else
        local latitudeText = string.format( '%.4f', event.latitude )
        currentLatitude = latitudeText
        latitude:setText( latitudeText )

        local longitudeText = string.format( '%.4f', event.longitude )
        currentLongitude = longitudeText
        longitude:setText( longitudeText )

        local altitudeText = string.format( '%.3f', event.altitude )
        altitude:setText( altitudeText )

        local accuracyText = string.format( '%.3f', event.accuracy )
        accuracy:setText( accuracyText )

        local speedText = string.format( '%.3f', event.speed )
        speed:setText( speedText )

        local directionText = string.format( '%.3f', event.direction )
        direction:setText( directionText )

        -- Note: event.time is a Unix-style timestamp, expressed in seconds since Jan. 11970
        local timeText = string.format( '%.0f', event.time )
        time:setText( timeText )
    end
end

-- Activate location listener
Runtime:addEventListener( "location", locationHandler )


No comments:

Post a Comment