Business App Map Error

No.  The request for an address takes time so it has a call back listener function that gets called once the data is available. If you’ve changed scenes and myMap gets removed, then that call back function fires but doesn’t have a map object to add the marker too.

I was thinking something like:

 for i = 1, #stadiumLocations do myMap:requestLocation(stadiumLocations[i], function(event) if myMap then addStadiums(event, i); end end) end

or something like that.

I just tried the above, but the same error happens.

Robert, I was able to fix it , there were other locations that I needed to do the check.

Now when I test the same code on an Android Device (Samsung Galaxy S6) I get this invalid latitude argument error:

SM-G920V: ERROR: Runtime error

May 09 10:24:58.521 SM-G920V: venues.lua:69: Function mapView:addMarker() was given an invalid ‘latitude’ argument. Was expecting a number.

                    SM-G920V: stack traceback:

                    SM-G920V: [C]: ?

                    SM-G920V: [C]: in function ‘addMarker’

                    SM-G920V: venues.lua:69: in function ‘addStadiums’

                    SM-G920V: /Users/aroldocarvalho/Docu

May 09 10:24:58.534 ments/_Corona/2018WorldCup/venues.lua:270: in function <venues.lua:270>

Sounds like the requestLocation() API was unable to find one of your locations. You should also test the event.isError value to make sure it was successful. See:  https://docs.coronalabs.com/api/event/mapLocation/index.html and https://docs.coronalabs.com/api/event/mapLocation/isError.html.

You can print out the reason why it failed (example in the last URL above) and see why it’s failing.

Rob

Robert, there are 12 locations, and they all work fine on iOS, but for some reason they don’t work on Android.

Latitude is returning nil and so when I they to print the reason the code fails because it is nil.  

I also made sure that the build.settings included these:

android = { usesPermissions = { -- Required by the MapView to fetch its contents from the Google Maps servers. "android.permission.INTERNET", -- Optional permission used to display current location via the GPS. "android.permission.ACCESS\_FINE\_LOCATION", -- Optional permission used to display current location via WiFi or cellular service. "android.permission.ACCESS\_COARSE\_LOCATION", "com.google.android.c2dm.permission.RECEIVE", }, usesFeatures = { -- If you set permissions "ACCESS\_FINE\_LOCATION" and "ACCESS\_COARSE\_LOCATION" above, -- then you may want to set up your app to not require location services as follows. -- Otherwise, devices that do not have location sevices (such as a GPS) will be unable -- to purchase this app in the app store. { name = "android.hardware.location", required = false }, { name = "android.hardware.location.gps", required = false }, { name = "android.hardware.location.network", required = false }, }, },

Can you post the relevant code for your handler with the print statement and copy/paste your console log from your Android device?

Rob

Here is the code:

local function mapLocationHandler(event) if event.isError then print( "Error: " .. event.errorMessage ) else print( "The specified string is at: " .. event.latitude .. ", " .. event.longitude ) end if myMap~=nil then myMap:setCenter( event.latitude, event.longitude, false ) myMap:setRegion( event.latitude, event.longitude, 35.0, 35.0, false) --print("adding office marker") local options = { title="Luzhniki Stadium", subtitle="Moscow", imageFile = { filename = "images/stadiummarker.png", baseDir = system.ResourcesDirectory }, listener = markerListener } result, errorMessage = myMap:addMarker( event.latitude, event.longitude, options ) if result then --print("everything went well") else print(errorMessage) end end end

Something is wrong about the way that Android is handling the MapView, if I minimize the app after the error and them bring it up again I can see it plotting the map markers on the screen behind the error. here is a screenshot with a nil error

You can’t use the “…” operator to build one long string out of other values if one of those values is nil.  I don’t know if this is the guilty line of code or not, but I’ll use it as an example:

print( "The specified string is at: " .. event.latitude .. ", " .. event.longitude )

Instead you need to:

print( "The specified string is at: ", event.latitude, ", ", event.longitude )

This of course won’t look that pretty since the comma’s turn into tabs, but it won’t error. Look at venues.lua line 283 and see where you’re using a variable called “longitude” and figure out why it’s nil.

Rob

Rob I did that, and the log from the Corona emulator, runing on the Samsung device is below.

The latitude and longitude is nil, but the “event.isError” is returning FALSE, it sounds like the “myMap:requestLocation” is returning empty. 

Since my app plots 12 map markers, I decided to plot only one. When I do that some times it plots one and some time it gives the nil error. For some reason the requestLocation on Android needs more time to find the location.

I am using the device connected to the WiFi.

The next step will be to pass the Latitude and Longitude numbers and not use the myMap:request.

This is either a bug or some build.settings parameters. I am not sure.

Here are the locations I am using:

stadiumLocations[1] = "Saint Petersburg Stadium,Russia, 197110" stadiumLocations[2] = "Fisht Stadium,Russia, 354340" stadiumLocations[3] = "Ekaterinburg Arena, Russia, 620028" stadiumLocations[4] = "Kazan Arena,Russia, 421001" stadiumLocations[5] = "Nizhny Novgorod Stadium, Russia, 603159" stadiumLocations[6] = "Kaliningrad Stadium, Russia, 236006" stadiumLocations[7] = "Spartak Stadium, Russia, 125424" stadiumLocations[8] = "Samara Arena, Russia, 443072" stadiumLocations[9] = "Rostov Arena, Russia, 344002" stadiumLocations[10] = "Volgograd Arena, Russia, 400005" stadiumLocations[11] = "Mordovia Arena, Russia, 430009"

On the iPhone they work fine and if I paste the locations on google map it finds all of them too.

SM-G920V: The specified string is at: nil , nil May 09 06:15:04.407 SM-G920V: The spe May 09 06:15:04.407 cified string is at: nil , nil SM-G920V: The specified string is at: nil , nil SM-G920V: The specified string is at: nil , nil SM-G920V: The specified string is at: nil , nil SM-G920V: The specified string is at: nil , nil May 09 06:15:04.410 SM-G920V: The specified string i May 09 06:15:04.411 s at: nil , nil May 09 06:15:04.411 SM-G920V: The specified string is at: nil , nil May 09 06:15:04.413 SM-G920V May 09 06:15:04.414 : The specified string is at: nil , nil May 09 06:15:04.415 SM-G920 May 09 06:15:04.416 V: The specified string is at: nil , nil May 09 06:15:04.431 SM-G920V: T May 09 06:15:04.431 he specified string is at: nil , nil SM-G920V: The specified string is at: nil , nil May 09 06:15:06.667 SM-G920V: ERROR: May 09 06:15:06.667 May 09 06:15:06.672 Runtime error May 09 06:15:06.672 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \< May 09 06:15:06.676 venues.lua:286\> May 09 06:15:06.676 SM-G920V: ERROR: Runtime error May 09 06:15:06.676 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: ? SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\> May 09 06:15:06.698 SM-G920V: ERROR: Runtime error May 09 06:15:06.698 SM-G920V: /Users/aroldocarvalho/Documents/\_Corona/201 May 09 06:15:06.700 8WorldCup/venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\> May 09 06:15:06.701 SM-G920V: ERROR: Runtime error May 09 06:15:06.701 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: ? SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\> May 09 06:15:06.701 SM-G920V: ERROR: Runtime error May 09 06:15:06.701 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\> May 09 06:15:06.701 SM-G920V: ERROR: Runtime error May 09 06:15:06.701 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: ? SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\> May 09 06:15:06.731 SM-G92 May 09 06:15:06.732 0V: ERROR: Runtime error May 09 06:15:06.732 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\> May 09 06:15:06.732 SM-G920V: ERROR: Runtime error May 09 06:15:06.732 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: ? SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\> SM-G920V: Loc Handler Error: May 09 06:15:06.732 SM-G920V: ERROR: Runtime error May 09 06:15:06.733 SM-G920V: venues.lua:85: Function mapView:setCenter() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: in function 'setCenter' SM-G920V: venues.lua:85: in function \<venues.lua:78\> May 09 06:15:06.733 SM-G920V: ERROR: Runtime error May 09 06:15:06.733 SM-G920V: venues.lua:85: Function mapView:setCenter() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: ? SM-G920V: [C]: in function 'setCenter' SM-G920V: venues.lua:85: in function \<venues.lua:78\> May 09 06:15:06.733 SM-G920V: ERROR: Runtime error May 09 06:15:06.733 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\> May 09 06:15:06.733 SM-G920V: ERROR: Runtime error May 09 06:15:06.733 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: ? SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\> May 09 06:15:06.733 SM-G920V: ERROR: Runtime error May 09 06:15:06.734 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\> May 09 06:15:06.734 SM-G920V: ERROR: Runtime error May 09 06:15:06.734 SM-G920V: venues.lua:74: Function mapView:addMarker() was given an invalid 'latitude' argument. Was expecting a number. SM-G920V: stack traceback: SM-G920V: [C]: ? SM-G920V: [C]: in function 'addMarker' SM-G920V: venues.lua:74: in function 'addStadiums' SM-G920V: venues.lua:286: in function \<venues.lua:286\>