Total Pageviews

Friday, May 30, 2014

Type Map (detail1)

នេះជា Type Map របស់ Corona SDK
សំរាប់ Map View អាចឪ្យ Developer integrate នៅ Map View មួយឬច្រើន ទៅក្នុងកម្មវិធី ហើយវាមាន two way communication between map contents & surrounding application, វារួមបញ្ចូលទាំង address or landmark lookup, កាធ្វើចំណាំនៅ Map with pins, & reverse geocoding (converting latitude/longtitude into the closest street address)
នេះជា Properties របស់វា
object.isLocationVisible
វាជា Read-Only Boolean value ដែល indicating ថាតើ user’s current location is visible នៅក្នុង area currently displayed on the map។ វាអាស្រ័យលើតំលៃប្រហាក់ប្រហែល ហើយវាអាចជា True នៅពេលដែលអ្នកប្រើស្ថិតនៅ slightly offscreen។ សំរាប់ Property របស់វាតែងតែជា false បើសិនជា current location is unknown
ចំណាំះ ដើម្បីឪ្យវា access current location នៅលើ Android, សូមបញ្ចូលវាទៅក្នុង permissions នៅក្នុង build.settings file
settings =
{
    android =
    {
        usesPermissions =
        {
            -- Permission to retrieve current location from the GPS.
            "android.permission.ACCESS_FINE_LOCATION",

            -- Permission to retrieve current location from WiFi or cellular service.
            "android.permission.ACCESS_COARSE_LOCATION",
        },
    },
}

សូមមើលកូដះ
local isLocVisible = myMap.isLocationVisible

object.isScrollEnabled
វាជា Boolean ដែលកំណត់ថាតើ អ្នកប្រើអាច Scroll the map by hand។ តំលៃដើមគឺ True, ការបញ្ចូលទៅជា false ក្នុងការការពារអ្នកប្រើ from scrolling the map។ សូមចំណាំថា a map អាច scrolled/panned តាមរយះ ​
Object:setCenter() & object:setRegion() functions, បើសិនជា this property គឺ false។ វាមានអត្ថប្រយោជន៏បើសិនជាចង់ឪ្យ map movement ដែលគ្រប់គ្រង់ដោយកម្មវិធី មិនមែនអ្នកប្រើ
សូមមើលកូដះ
myMap.isScrollEnabled = false
myMap.isZoomEnabled = false

object.isZoomEnabled
វាជា Boolean ដែលកំនត់ថាតើអ្នកប្រើប្រាស់ប្រើ pinch/zoom gestures ទៅកាន់ zoom map។ តំលៃដើមជា false ក្នុងការការពារអ្នកប្រើប្រាស់ចេញពី zooming the map។ សូមចំណាំថា a map can still be zoomed តាមរយះ object:setRegion() function ទោះបីជា Property បានបញ្ចូលទៅជា false
សូមមើលកូដះ
myMap.isScrollEnabled = false
myMap.isZoomEnabled = false

object.mapType
វាជា String ដែលកំណត់នៅ ប្រភេទរបស់ map display។ តំលៃរបស់វាអាចជា standard (default)/ saterllite/ hybrid
សូមមើលកូដះ
Local myMap = native.newMapView (0,0, display.contentWidth, display.contentHeight)
myMap.mapType = “satellite”

Methods
object:addMarker()
ប្រើសំរាប់បន្ថែម pin ទៅកាន់ Map តាមទីតាំងច្បាស់លាស់ណាមួយ។ វានឹងបង្ហាញនៅ title & subtitle ដែលបង្ហាញលើ small popup នៅពេលដែល pin ត្រូវបាន Touched។ ហ្វាំងសិននេះអាចត្រឡប់ជា identification number សំរាប់ marker ដែលបានបន្ថែម ឬក៏ nil បើសិនជា failure។ លេខនេះអាចប្រើជាមួយនឹង object:removeMarker() to remove a marker
Syntax: object:addMarker (latitude, longitude)
Object:addMarker (latitude, longitude, options)
Latitude (តំរូវការ) វាជាចំនួនលេខដែល marker’s latitude in degrees
Longitude (តំរូវការ) វាជាចំនួនលេខដែលជា marker’s longitude in degrees
Options(ជំរើស) វាជាតារាងដែលជា table of options សំរាប់ marker

Options reference
Options.title( ជំរើស) វាជា String ដែលជា Title បង្ហាញលើ pop up ដែលបង្ហាញនៅពេលអ្នកប្រើប្រាស់ taps the marker
Options.subtitle (ជំរើស) វាជា String ដែល subtitle បង្ហាញនៅលើ pop up ដែលបង្ហាញនៅពេលអ្នកប្រើ taps the marker
Options.listener (ជំរើស)
វាជាហ្វាំងសិនដែល ​listener នឹងត្រូវបានហៅនៅពេលដែល marker ត្រូវបាន tapped
Options.imageFile(ជំរើស)
វាជា String ដែលជាឈ្មោះរបស់ image ត្រូវប្រើសំរាប់ markerthe default base director is the resource directory។ វាអាចជា ​table of the form {baseDir =, filename =} វានឹងប្រើនៅ dynamic image selection។ ចំណែក coordinates are returned as a mapMarker


សូមមើលកូដះ
local function markerListener(event)
    print( "type: ", event.type )  --event type
    print( "markerId: ", event.markerId )  --id of the marker that was touched
    print( "lat: ", event.latitude )  --latitude of the marker
    print( "long: ", event.longitude )  --longitude of the marker
end

local myMap = native.newMapView( 0, 0, 300, 220 )
myMap.x = display.contentCenterX
myMap.y = display.contentCenterY

-- This will look in the resources directory for the image file.
local options =
{
    title = "Displayed Title",
    subtitle = "subtitle text",
    listener = markerListener,
    imageFile =  "someImage.png",
}

-- Alternatively, this looks in the specified directory for the image file.
--[[
local options =
{
    title = "Displayed Title",
    subtitle = "subtitle text",
    listener = markerListener,
    imageFile =
    {
        filename = "someImage.png",
        baseDir = system.TemporaryDirectory
    }
}
--]]

local result, errorMessage = myMap:addMarker( 37.331692, -122.030456, options )
if ( result ) then
    print( "everything went well" )
else
    print( errorMessage )
end

object:getAddressLocation() វាត្រូវបានប្រើជំនួសដោយ object:requestLocation()

(Deprecated: Use object:requestLocation() instead.)
object:getUserLocation()
ប្រើសំរាប់ត្រឡប់នៅ table ដែលផ្ទុកនៅតំលៃសំរាប់អ្នកប្រើប្រាស់ current location។ សំរាប់តារាងវាដូចគ្នានឹង GPS location events។ បើសិនជាវាត្រឡប់ជា location.errorCode field មិនត្រូវបាន nil។ ពេលនោះវានឹង indicates ថាតើ application has failed to fetch នៅ user’s current location។ វាអាចកើតឡើងនៅតាមហេតុផលនេះះ
Current location has not been received yet
Current location tracking is not available on the device
The application does not have permission
Syntax: object:getUserLocation()

ចំណាំះ
ដើម្បីទាញយកនៅ current location នៅលើ Android ត្រូវតែដាក់ permissions នៅក្នុង build.settings បើមិនទេហ្វាំងសិននេះនឹងត្រឡប់នៅ location table with the location.errorCode field set and current location marker នឹងមិនបង្ហាញលើ Map ទេ
settings =
{
    android =
    {
        usesPermissions =
        {
            -- Permission to retrieve current location from the GPS.
            "android.permission.ACCESS_FINE_LOCATION",

            -- Permission to retrieve current location from WiFi or cellular service.
            "android.permission.ACCESS_COARSE_LOCATION",
        },
    },
}

សូមមើលកូដះ
 local myMap = native.newMapView( 0, 0, 320, 480 )
myMap.x = display.contentCenterX
myMap.y = display.contentCenterY

local locationTable  = myMap:getUserLocation()
local locationtxt = display.newText( "My location is: ", 0, 0, native.systemFont, 16 )

if ( locationTable.errorCode ) then
    locationtxt.text = locationtxt.text .. locationTable.errorMessage
else
    locationtxt.text = locationtxt.text .. locationTable.latitude .. ", " ..locationTable.longitude
end

No comments:

Post a Comment