Stuck on this problem for months and still no resolution

Hi everyone;

I am so close and yet so far from finishing my app, its a good thing I am not dependent for it to live on.

I have posted several times and still no resolution. Here is the problem code.

module(..., package.seeall);  
  
function new()  
 local localGroup = display.newGroup();  
  
 local bg = display.newImageRect("images/elpasoatnight.png", \_W,\_H);  
 bg:setReferencePoint(display.CenterReferencePoint);  
 bg.x = \_W/2; bg.y = \_H/2;  
 localGroup:insert(bg);  
--  
-- display credits  
--  
 credits = display.newText ( "Xela Development", 0, 0, "Helvetica-Bold", 12)  
 credits:setTextColor (255,128,255)  
 credits.x = 400; credits.y = 300;  
 localGroup:insert(credits);  
--  
-- back button  
--  
 local back = ui.newButton{  
 default = "images/buttonBlueSmall.png",  
 over = "images/buttonBlueSmallOver.png",  
 onPress = "menu",  
 text = "back",  
 size = 10,  
 emboss=true  
 }  
  
 back.x = 35; back.y = display.statusBarHeight-1;  
 back.scene = "menu"  
 localGroup:insert(back);  
--  
-- check place to join  
--  
 local places = ui.newButton{  
 default = "images/buttonBlueSmall.png",  
 over = "images/buttonBlueSmallOver.png",  
 onPress = "mapAddressHandler",  
 text = "places to join",  
 size = 9,  
 emboss=true  
 }  
  
 places.x = 105; places.y = display.statusBarHeight-1;  
 places.scene = "mapAddressHandler"  
 localGroup:insert(places);  
--  
-- setup for finding my address  
--  
 myMap = native.newMapView( 20, 20, 300, 220 )  
 myMap.mapType = "standard"   
 myMap:nearestAddress( 38.898748, -77.037684)  
 myMap.x = display.contentWidth / 2  
 myMap.y = 120  
 localGroup:insert(myMap);   
--  
-- display my address  
--  
 local function mapAddressHandler( event )  
 -- handle mapAddress event here  
 print( "Check in address: " .. event.city .. ", " .. event.country )  
 end  
--  
-- event listener  
--  
  
Runtime:addEventListener( "mapAddress", mapAddressHandler )  
 return localGroup;  
end  

Code is a module that gets called by “director” from a menu. I get no errors but it looks like the event listener is not firing. I am a little confused about how I call the event listener. Basically its a button but I am not getting to “mapaddresshandler”.

I am getting the map, even though its pointed to China when I am entering in the coordinates that GPS sampler program is giving. What I am really after is for “mapaddresshandler” to give the place down to city and address.

Could someone tell me what I am doing wrong please, it would be greatly appreciated.

Thanks [import]uid: 95689 topic_id: 26997 reply_id: 326997[/import]

ok;

I found one thing, I am doing a print and I don’t know where the output of the console goes when you build for the device. Where does it go?

Actually, I would like to do a msg like format like google when you click on the pin in a map. How do I do that?

Thanks [import]uid: 95689 topic_id: 26997 reply_id: 109553[/import]

theres an awful lot of guesswork in there.

You have a scene called mapAddressHandler
and a function of the same name
places.scene = “mapAddressHandler”

does this imply that you want to change scene when the button is clicked?

onPress = “mapAddressHandler”, does that.
But the function mapAddressHandler has to be higher up in the code if that is going to work.

maybe this:

[code]

– display my address

local function mapAddressHandler( event )
– handle mapAddress event here
print( "Check in address: " … event.city … ", " … event.country )
end
check place to join

local places = ui.newButton{
default = “images/buttonBlueSmall.png”,
over = “images/buttonBlueSmallOver.png”,
onPress = “mapAddressHandler”,
text = “places to join”,
size = 9,
emboss=true
}

places.x = 105; places.y = display.statusBarHeight-1;
localGroup:insert(places);

– setup for finding my address

myMap = native.newMapView( 20, 20, 300, 220 )
myMap.mapType = “standard”
myMap:nearestAddress( 38.898748, -77.037684)
myMap.x = display.contentWidth / 2
myMap.y = 120
localGroup:insert(myMap);

return localGroup;
[/code] [import]uid: 108660 topic_id: 26997 reply_id: 109560[/import]

@jeff472

Tried it as you suggested with same results. Here is the updated code:

module(..., package.seeall);  
  
function new()  
 local localGroup = display.newGroup();  
  
 local bg = display.newImageRect("images/elpasoatnight.png", \_W,\_H);  
 bg:setReferencePoint(display.CenterReferencePoint);  
 bg.x = \_W/2; bg.y = \_H/2;  
 localGroup:insert(bg);  
--  
-- display credits  
--  
 credits = display.newText ( "Xela Development", 0, 0, "Helvetica-Bold", 12)  
 credits:setTextColor (255,128,255)  
 credits.x = 400; credits.y = 300;  
 localGroup:insert(credits);  
--  
-- back button  
--  
 local back = ui.newButton{  
 default = "images/buttonBlueSmall.png",  
 over = "images/buttonBlueSmallOver.png",  
 onPress = "menu",  
 text = "back",  
 size = 10,  
 emboss=true  
 }  
  
 back.x = 35; back.y = display.statusBarHeight-1;  
 back.scene = "menu"  
 localGroup:insert(back);  
  
--  
-- display my address  
--  
 local function mapAddressHandler( event )  
 -- handle mapAddress event here  
 textout( "Check in address: " .. event.city .. ", " .. event.country )  
-- print( "Check in address: " .. event.city .. ", " .. event.country )  
 end   
--  
-- check place to join  
--  
 local places = ui.newButton{  
 default = "images/buttonBlueSmall.png",  
 over = "images/buttonBlueSmallOver.png",  
 onPress = "mapAddressHandler",  
 text = "places",  
 size = 9,  
 emboss=true  
 }  
  
 places.x = 105; places.y = display.statusBarHeight-1;  
 places.scene = "mapAddressHandler"  
 localGroup:insert(places);  
--  
-- setup for finding my address  
--  
 myMap = native.newMapView( 20, 20, 350, 250 )  
 myMap.mapType = "standard"   
 myMap:nearestAddress( 31.847000, -106.589200)  
 myMap.x = display.contentWidth / 2  
 myMap.y = 120  
 localGroup:insert(myMap);   
  
  
--   
-- TEXT OUT - Quick Print  
--   
local textoutline = 1  
local function textout( text )  
  
 if textoutline \> 24 then textoutline = 1 end  
 if textoutline == 1 then  
 local background = display.newRect(  
 0, 0,  
 display.contentWidth,  
 display.contentHeight  
 )  
 background:setFillColor(254,254,254)  
 end  
  
 local myText = display.newText( text, 0, 0, nil, display.contentWidth/23 )  
  
 myText:setTextColor(200,200,180)  
 myText.x = math.floor(display.contentWidth/2)  
 myText.y = (display.contentWidth/19) \* textoutline - 5  
  
 textoutline = textoutline + 1  
end   
--  
-- event listener  
--  
function changeScene(e)  
 if(e.phase =="ended") then  
 director:changeScene(e.target.scene);  
 end  
 end   
  
  
back:addEventListener("touch", changeScene);  
Runtime:addEventListener( "mapAddress", mapAddressHandler );  
 return localGroup;  
end  

When executing mapaddresshandler, I don’t want to change scenes just print the city, address. Well city, country for now. Also, like I mentioned, can’t print on device, so tried textout but no results. I believe textout is for just text, don’t know how it handles variables.

Thanks
[import]uid: 95689 topic_id: 26997 reply_id: 109590[/import]

Is it possible that from the time you instantiate the map ( your call to native.newMapView ), to the time you call to get the address ( myMap:nearestAddress ), there is no listener defined?

I see you assign the listener at a totally different time, possibly when there isn’t even a map (didn’t follow when changeScene gets called).

Perhaps if you move the call to Runtime:addEventListener( “mapAddress”, mapAddressHandler ) up to right after the map is declared, but before the myMap:nearestAddress call… Ya? [import]uid: 79933 topic_id: 26997 reply_id: 109617[/import]