native mapView problem

I get the following example http://docs.coronalabs.com/api/library/native/newMapView.html#functions-and-properties

and just only add heabar object

After you play (zoom-in, zoom-out ) with map object disappear 

Corona version 2014.2511 (2014.11.18)

Iphone version 4s, 6

Could you please advise?

local widget = require( "widget" ) local headbar = display.newRoundedRect(0, 0, 320, 50, 0) headbar.alpha = 1 headbar.anchorX = 0 headbar.anchorY = 0 headbar:toFront() headbar:setFillColor(200/255, 0/255, 0/255 ) local locationNumber = 1 --a counter to display on location labels local currentLocation, currentLatitude, currentLongitude local outline = display.newRect( 16, 16, 308, 228 ) outline.x = display.contentCenterX outline.y = display.contentCenterY outline:setFillColor( 1, 1, 1, 0.2 ) if ( system.getInfo( "environment" ) == "simulator" ) then local simulatorMessage = "Maps not supported in Corona Simulator.\nYou must build for iOS or Android to test native.newMapView() support." local label = display.newText( simulatorMessage, 36, 40, 270, 0, native.systemFont, 12 ) label.anchorX = 0 label.anchorY = 0 end -- Create a native MapView (requires Xcode iOS Simulator build or device build) local myMap = native.newMapView( 20, 20, 300, 220 ) myMap.x = display.contentCenterX myMap.y = display.contentCenterY if ( myMap ) then -- Display a normal map with vector drawings of the streets. -- Other mapType options are "satellite" and "hybrid". myMap.mapType = "normal" myMap.x = display.contentCenterX myMap.y = display.contentCenterY -- Initialize map to a real location, since default location (0,0) is not very interesting myMap:setCenter( 37.331692, -122.030456 ) -- This is returned as a mapLocation event local function mapLocationListener(event) print("map tapped latitude: ", event.latitude) print("map tapped longitude: ", event.longitude) end myMap:addEventListener("mapLocation", mapLocationListener) end -- A function to handle the "mapAddress" event (also known as "reverse geocoding", ie: coordinates -\> string). local function mapAddressHandler( 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, imageFile = "bar.png" } ) end end local buttonRelease = function( event ) -- Do not continue if a MapView has not been created. if ( myMap == nil ) then return end -- Fetch the user's current location currentLocation = myMap:getUserLocation() if currentLocation.errorCode then -- Current location is unknown if the "errorCode" property is not nil. currentLatitude = 0 currentLongitude = 0 native.showAlert( "Error", currentLocation.errorMessage, { "OK" } ) else -- Current location data was received. -- Move map so that current location is at the center. currentLatitude = currentLocation.latitude currentLongitude = currentLocation.longitude myMap:setRegion( currentLatitude, currentLongitude, 0.01, 0.01, true ) -- Look up nearest address to this location (this is returned as a "mapAddress" event, handled above) myMap:nearestAddress( currentLatitude, currentLongitude, mapAddressHandler ) end end local button = widget.newButton { label = "Get Current Location", onRelease = buttonRelease } button.x = display.contentCenterX button.y = 390

Hi @maverick.st,

Can you check the Terminal/console and see if you’re getting any error messages?

Thanks,

Brent

No errors, 

The strange thing is that object not disappear always every time i run it

Jan  9 09:27:22 Babis-iPhone CommCenter[19] <Error>: throttleCallBack(): Clearing throttle timer on context ID 0

Jan  9 09:27:22 Babis-iPhone CommCenter[19] <Error>: throttleCallBack(): Clearing throttle timer on context ID 1

Jan  9 09:27:22 Babis-iPhone CommCenter[19] <Error>: throttleCallBack(): Clearing throttle timer on context ID 2

Jan  9 09:27:22 Babis-iPhone CommCenter[19] <Error>: throttleCallBack(): Clearing throttle timer on context ID 3

Hi @maverick.st,

Can I ask you to please test our maps sample project, and report if the same issue occurs in your tests? It’s located in your local Corona application folder here:

CoronaSDK > SampleCode > Interface > MapView

Thanks,

Brent

I have check the demo and working…

But the strange thing is that i get the code (copy paste) and in my app not working correct

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local myMap2 -- Clear previous scene storyboard.removeAll() -- local forward references should go here -- --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view end -- Called BEFORE scene has moved onscreen: function scene:willEnterScene( event ) local group = self.view end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view local widget = require( "widget" ) local function Goto() storyboard.gotoScene( "menu" ) return true end local locationNumber = 1 -- a counter to display on location labels local currentLocation, currentLatitude, currentLongitude local headbar = display.newRoundedRect(0, 0, 320, 40, 0) headbar.alpha = 1 headbar.anchorX = 0.0 headbar.anchorY = 0.0 headbar:toFront() headbar:setFillColor(210/255, 0/255, 0/255 ) group:insert(headbar) local back = display.newImage("images/back\_black.png", 30, 30); back.x = 35 back.y = 25 back.width = 55 back.height = 29 back:toFront() back.alpha = 1 group:insert(back) back:addEventListener("tap" ,Goto) myMap2 = native.newMapView( 20, 20, 300, 220 ) -- myMap.anchorX = 0.0 -- TopLeft anchor -- myMap.anchorY = 0.0 -- TopLeft anchor if myMap2 then -- Display a normal map with vector drawings of the streets. -- Other mapType options are "satellite" and "hybrid". --myMap2.mapType = "normal" -- The MapView is just another Corona display object and can be moved, resized, etc. myMap2.x = display.contentWidth / 2 myMap2.y = 120 -- Initialize map to a real location, since default location (0,0) is not very interesting myMap2:setCenter( 37.331692, -122.030456 ) end end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view myMap2:removeSelf() myMap2 = nil end -- Called AFTER scene has finished moving offscreen: function scene:didExitScene( event ) local group = self.view end -- Called prior to the removal of scene's "view" (display view) function scene:destroyScene( event ) local group = self.view end -- Called if/when overlay scene is displayed via storyboard.showOverlay() function scene:overlayBegan( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end -- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay() function scene:overlayEnded( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "willEnterScene" event is dispatched before scene transition begins scene:addEventListener( "willEnterScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "didExitScene" event is dispatched after scene has finished transitioning out scene:addEventListener( "didExitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) -- "overlayBegan" event is dispatched when an overlay scene is shown scene:addEventListener( "overlayBegan", scene ) -- "overlayEnded" event is dispatched when an overlay scene is hidden/removed scene:addEventListener( "overlayEnded", scene ) --------------------------------------------------------------------------------- return scene

Hi @maverick.st,

I would need a better description of “not working” to help you further.

Thanks,

Brent

Hi Brent

I have a same situation about currentLocation.

Of course your MapView sample working at my mac.

But that are not using composer API.

I use composer API.

I think it may something wrong behavior.

Thanks,

Tetsuo

Hi Tetsuo,

Can you be more specific about what is not working? Remember that when you’re loading a map and requesting the current location, it may take a few seconds for the device GPS to “activate” and find the location. So, you might want to use the code example that is shown here:

http://docs.coronalabs.com/api/type/Map/getUserLocation.html

This basically uses a timer to check every 1 second for the GPS result, and when it finds the result, it proceeds to update the data.

Best regards,

Brent

Hi @maverick.st,

Can you check the Terminal/console and see if you’re getting any error messages?

Thanks,

Brent

No errors, 

The strange thing is that object not disappear always every time i run it

Jan  9 09:27:22 Babis-iPhone CommCenter[19] <Error>: throttleCallBack(): Clearing throttle timer on context ID 0

Jan  9 09:27:22 Babis-iPhone CommCenter[19] <Error>: throttleCallBack(): Clearing throttle timer on context ID 1

Jan  9 09:27:22 Babis-iPhone CommCenter[19] <Error>: throttleCallBack(): Clearing throttle timer on context ID 2

Jan  9 09:27:22 Babis-iPhone CommCenter[19] <Error>: throttleCallBack(): Clearing throttle timer on context ID 3

Hi @maverick.st,

Can I ask you to please test our maps sample project, and report if the same issue occurs in your tests? It’s located in your local Corona application folder here:

CoronaSDK > SampleCode > Interface > MapView

Thanks,

Brent

I have check the demo and working…

But the strange thing is that i get the code (copy paste) and in my app not working correct

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local myMap2 -- Clear previous scene storyboard.removeAll() -- local forward references should go here -- --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view end -- Called BEFORE scene has moved onscreen: function scene:willEnterScene( event ) local group = self.view end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view local widget = require( "widget" ) local function Goto() storyboard.gotoScene( "menu" ) return true end local locationNumber = 1 -- a counter to display on location labels local currentLocation, currentLatitude, currentLongitude local headbar = display.newRoundedRect(0, 0, 320, 40, 0) headbar.alpha = 1 headbar.anchorX = 0.0 headbar.anchorY = 0.0 headbar:toFront() headbar:setFillColor(210/255, 0/255, 0/255 ) group:insert(headbar) local back = display.newImage("images/back\_black.png", 30, 30); back.x = 35 back.y = 25 back.width = 55 back.height = 29 back:toFront() back.alpha = 1 group:insert(back) back:addEventListener("tap" ,Goto) myMap2 = native.newMapView( 20, 20, 300, 220 ) -- myMap.anchorX = 0.0 -- TopLeft anchor -- myMap.anchorY = 0.0 -- TopLeft anchor if myMap2 then -- Display a normal map with vector drawings of the streets. -- Other mapType options are "satellite" and "hybrid". --myMap2.mapType = "normal" -- The MapView is just another Corona display object and can be moved, resized, etc. myMap2.x = display.contentWidth / 2 myMap2.y = 120 -- Initialize map to a real location, since default location (0,0) is not very interesting myMap2:setCenter( 37.331692, -122.030456 ) end end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view myMap2:removeSelf() myMap2 = nil end -- Called AFTER scene has finished moving offscreen: function scene:didExitScene( event ) local group = self.view end -- Called prior to the removal of scene's "view" (display view) function scene:destroyScene( event ) local group = self.view end -- Called if/when overlay scene is displayed via storyboard.showOverlay() function scene:overlayBegan( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end -- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay() function scene:overlayEnded( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "willEnterScene" event is dispatched before scene transition begins scene:addEventListener( "willEnterScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "didExitScene" event is dispatched after scene has finished transitioning out scene:addEventListener( "didExitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) -- "overlayBegan" event is dispatched when an overlay scene is shown scene:addEventListener( "overlayBegan", scene ) -- "overlayEnded" event is dispatched when an overlay scene is hidden/removed scene:addEventListener( "overlayEnded", scene ) --------------------------------------------------------------------------------- return scene

Hi @maverick.st,

I would need a better description of “not working” to help you further.

Thanks,

Brent

Hi Brent

I have a same situation about currentLocation.

Of course your MapView sample working at my mac.

But that are not using composer API.

I use composer API.

I think it may something wrong behavior.

Thanks,

Tetsuo

Hi Tetsuo,

Can you be more specific about what is not working? Remember that when you’re loading a map and requesting the current location, it may take a few seconds for the device GPS to “activate” and find the location. So, you might want to use the code example that is shown here:

http://docs.coronalabs.com/api/type/Map/getUserLocation.html

This basically uses a timer to check every 1 second for the GPS result, and when it finds the result, it proceeds to update the data.

Best regards,

Brent