Map - requestLocation giving runtime error stating third argument?

I am trying to get mapview working to display locations out of a table,  stage one was to get it to show the current location. this worked fine after finding some code to make it wait until the map is ready, however now I am trying to get the location from an address string.

[lua]local function setmapcenter()
    if myMap then
      local current_location = myMap.getUserLocation()
      current_address = myMap:nearestAddress(current_location.latitude, current_location.longitude, mapAddressHandler)
      local loc = myMap:requestLocation(“131 Leichhardt street”, mapLocationHandler)
      myMap:setRegion( loc.latitude, loc.longitude, 0.01, 0.01, true )
    end
end

local function mapLocationHandler( 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 } )
        native.showAlert( “location”, “It supposedly worked”, { “OK” } )
    end
end[/lua]

When it runs  myMap:requestLocation on the actual device I get this runtime error :

Bed self argument to requestLocation (the third argument of requestLocation should be a listener.)

The problem is, the API docs says :

object:requestLocation( location, resultHandler )

location (required)

String. The address, intersection, or landmark.

Do I need to add an event listener line like

myMap:addEventListener( “mapLocationHandler”, mapLocationHandler)

becuase I am using storyboard?  (I actually tried the above and it did not help)

Not a noob question?

If I move the code onto a button, it works without giving this error, if I place it back into a timer that runs 5 seconds after the page loads (well after the map is ready) it gives this error :frowning:

[lua]local function setmap()
  if myMap then
    timer.cancel(setmaptimer)
    --myMap:setCenter(currentLocation.latitude, currentLocation.longitude, true)
    myMap:requestLocation(storyboard.detail_data[3], mapLocationHandler)
  end
end[/lua]

when the code above executes, the error is given

[lua]local function button_call_release()
  myMap:requestLocation(storyboard.detail_data[3], mapLocationHandler)
  return true
end[/lua]

Pressing this button works without an error and displays the location and marker

[lua]setmaptimer = timer.performWithDelay(5000, setmap, -1)[/lua]

My timer

[lua]  myMap = native.newMapView( (display.contentCenterX * 0.7) + storyboard.side_padding, display.contentHeight * 0.7 + storyboard.top_padding, display.contentWidth * 0.70 , display.contentHeight / 3 )
 
  if myMap then
    --myMap:addEventListener(“mapLocation”, mapTapListener)
    myMap:addEventListener( “mapLocation”, mapLocationHandler)
    – Initialize map to a real location, since default location (0,0) is not very interesting
    – Display a normal map with vector drawings of the streets.
      – Other mapType options are “satellite” and “hybrid”.
    myMap:setCenter( -27.462748, 153.025172 )
      myMap.mapType = “normal”
  end[/lua]

My map creation

I can post attach the entire project if someone in-the-know wants to help

This has me completely stumped, why does it ask for a third argument in when used from a timer?

I think you have a scoping problem.  This line:

local loc = myMap:requestLocation(“131 Leichhardt street”, mapLocationHandler)

comes before this line:

 

local function mapLocationHandler( event )

Therefore mapLocationHandler is nil when we first parse the code.  I would suggest flipping the two functions in your code.

Rob

hey nice catch,  I thought it was pre-compiled and so order wouldnt matter!

Not a noob question?

If I move the code onto a button, it works without giving this error, if I place it back into a timer that runs 5 seconds after the page loads (well after the map is ready) it gives this error :frowning:

[lua]local function setmap()
  if myMap then
    timer.cancel(setmaptimer)
    --myMap:setCenter(currentLocation.latitude, currentLocation.longitude, true)
    myMap:requestLocation(storyboard.detail_data[3], mapLocationHandler)
  end
end[/lua]

when the code above executes, the error is given

[lua]local function button_call_release()
  myMap:requestLocation(storyboard.detail_data[3], mapLocationHandler)
  return true
end[/lua]

Pressing this button works without an error and displays the location and marker

[lua]setmaptimer = timer.performWithDelay(5000, setmap, -1)[/lua]

My timer

[lua]  myMap = native.newMapView( (display.contentCenterX * 0.7) + storyboard.side_padding, display.contentHeight * 0.7 + storyboard.top_padding, display.contentWidth * 0.70 , display.contentHeight / 3 )
 
  if myMap then
    --myMap:addEventListener(“mapLocation”, mapTapListener)
    myMap:addEventListener( “mapLocation”, mapLocationHandler)
    – Initialize map to a real location, since default location (0,0) is not very interesting
    – Display a normal map with vector drawings of the streets.
      – Other mapType options are “satellite” and “hybrid”.
    myMap:setCenter( -27.462748, 153.025172 )
      myMap.mapType = “normal”
  end[/lua]

My map creation

I can post attach the entire project if someone in-the-know wants to help

This has me completely stumped, why does it ask for a third argument in when used from a timer?

I think you have a scoping problem.  This line:

local loc = myMap:requestLocation(“131 Leichhardt street”, mapLocationHandler)

comes before this line:

 

local function mapLocationHandler( event )

Therefore mapLocationHandler is nil when we first parse the code.  I would suggest flipping the two functions in your code.

Rob

hey nice catch,  I thought it was pre-compiled and so order wouldnt matter!