我是新來使用corona sdk.
獲得一個企圖指數當地「我的地圖」(一個零值)
我試圖添加引腳映射視圖把我的代碼加入到做我不斷收到這個錯誤
企圖指數當地「我的地圖」(一個零值)
我看的東西了,有人也有類似的問題,他們只是有當地MYMAP添加到頂部。我試過了,但沒有奏效。我希望有人能幫我找出問題所在。
感謝您的幫助=)
local widget = require("widget")
local myMap
local locationNumber = 1 -- a counter to display on location labels
local currentLocation, currentLatitude, currentLongitude
local background = display.newImage("bkg_grass.png", true)
background.x = display.contentWidth/2
background.y = display.contentHeight/2
local shadow = display.newRect(7, 7, 306, 226)
shadow.anchorX = 0.0 -- TopLeft anchor
shadow.anchorY = 0.0 -- TopLeft anchor
shadow:setFillColor(0, 0, 0, 120/255)
local simulatorMessage = "Maps not supported in Corona Simulator.\n\nYou must build for iOS or Android to test MapView support."
local label = display.newText(simulatorMessage, 20, 70, shadow.contentWidth - 10, 0, native.systemFont, 14)
label.anchorX = 0.0 -- TopLeft anchor
label.anchorY = 0.0 -- TopLeft anchor
local myMap = native.newMapView(20, 20, display.contentWidth, display.actualContentHeight*.7)
if myMap then
myMap.mapType = "normal"
myMap.x = display.contentWidth/2
myMap.y = 400
myMap:setCenter(37.331692, -122.030456)
end
local function markerListener(event)
print("type: ", event.type) -- event
print("markerId: ", event.markerId) -- if of the marker that was touched
print("lat: ", event.latitude) -- latitude of the marker
print("long: ", event.longitude) -- longitude of the marker
end
local options =
{
title = "Displayed Title",
subtitle = "subtitle text",
listener = markerListener,
imageFile =
{
filename = "someImage.png",
baseDir = system.TemporaryDirectory
}
}
local options1 =
{
title = "Displayed Title",
subtitle = "subtitle text",
listener = markerListener,
imageFile = "someImage.png",
}
local result, errorMessage = myMap:addMarker(37.331692, -122.030456, options)
if result then
print("everything went well")
else
print(errorMessage)
end
-- A function to handle the "mapAddress" event (also known as "reverse geocoding", ie: coordinates -> string).
local mapAddressHandler = function(event)
if event.isError then
-- Failed to receive location information.
native.showAlert("Error", event.errorMessage, { "OK" })
else
-- Location information received. Display it.
local locationText =
"Latitude: " .. currentLatitude ..
", Longitude: " .. currentLongitude ..
", Address: " .. (event.streetDetail or "") ..
" " .. (event.street or "") ..
", " .. (event.city or "") ..
", " .. (event.region or "") ..
", " .. (event.country or "") ..
", " .. (event.postalCode or "")
native.showAlert("You Are Here", locationText, { "OK" })
end
end
-- A function to handle the "mapLocation" event (also known as "forward geocoding", ie: string -> coordinates).
local mapLocationHandler = function(event)
if event.isError then
-- Location name not found.
native.showAlert("Error", event.errorMessage, { "OK" })
else
-- Move map so this location is at the center
-- (The final parameter toggles map animation, which may not be visible if moving a large distance)
myMap:setCenter(event.latitude, event.longitude, true)
-- Add a pin to the map at the new location
markerTitle = "Location " .. locationNumber
locationNumber = locationNumber + 1
myMap:addMarker(event.latitude, event.longitude, { title=markerTitle, subtitle=inputField.text })
end
end
請標記錯誤是哪一行,沒有任何myMap行會跳出來,因爲有問題 – Schollii
StackOverflow不是「發佈您的所有代碼」網站並使我們進行調試。發佈代碼片段,以便我們可以幫助您解決問題。 –