attempt to index local 'myMap' (a nil value) の解決方法を知りたいのですが。

146 views
Skip to first unread message

hosokawa

unread,
Jan 8, 2016, 5:20:34 AM1/8/16
to 日本コロナの会
corona sdk の API の google map 活用のサンプル が 動かないです。
コンパイルすると、

C:\Users\hosokawa\Documents\Corona Projects\Orienteering\main.lua:3: attempt to index local 'myMap' (a nil value)

だれか解決方法を教えて下さい。 もしかして、Androidはgoogle map 使えないというオチですか。
-- main.lua 

-- Create a native map view
local myMap = native.newMapView( 20, 20, 280, 360 )
myMap.x = display.contentCenterX

local attempts = 0

local locationText = display.newText( "Location: ", 0, 400, native.systemFont, 16 )
locationText.anchorY = 0
locationText.x = display.contentCenterX

local function locationHandler( event )

    local currentLocation = myMap:getUserLocation()

    if ( currentLocation.errorCode or ( currentLocation.latitude == 0 and currentLocation.longitude == 0 ) ) then
        locationText.text = currentLocation.errorMessage

        attempts = attempts + 1

        if ( attempts > 10 ) then
            native.showAlert( "No GPS Signal", "Can't sync with GPS.", { "Okay" } )
        else
            timer.performWithDelay( 1000, locationHandler )
        end
    else
        locationText.text = "Current location: " .. currentLocation.latitude .. "," .. currentLocation.longitude
        myMap:setCenter( currentLocation.latitude, currentLocation.longitude )
        --myMap:addMarker( currentLocation.latitude, currentLocation.longitude )
    end
end

locationHandler()


--  build.setting

settings =
{
    android =
    {
        usesPermissions =
        {
        “android.permission.INTERNET”,
        “android.permission.ACCESS_FINE_LOCATION”,
        “android.permission.ACCESS_COARSE_LOCATION”,
        },
    },
}

C.C.

unread,
Jan 8, 2016, 10:46:40 AM1/8/16
to coro...@googlegroups.com
C.C. です、ソース何も見てませんが(笑

CoronaSDK Simulator の サンプル で MapView というのがありますが、
あれをコンパイル実行してみたことがありますか?
いま、ちょっとコンパイルしましたが、何の問題もなく表示されてい
ますけど・・ (^^;;

もし、動作させる方法がわからないなら、動いているサンプルから切
り出す方が簡単ですので、こちらから切り出してみてください。

hosokawa

unread,
Jan 9, 2016, 1:26:29 AM1/9/16
to 日本コロナの会
C.C.様

サンプルにあったとは知らずにおりました。 ご指摘ありがとうございます。 無事稼動しました。
 今後ともよろしくお願いします。
Reply all
Reply to author
Forward
0 new messages