I/Corona ( 9276): {
I/Corona ( 9276): “bytesEstimated”:2,
I/Corona ( 9276): “bytesTransferred”:2,
I/Corona ( 9276): “name”:“networkRequest”,
I/Corona ( 9276): “phase”:“ended”,
I/Corona ( 9276): “requestId”:"<type ‘userdata’ is not supported by JSON.>",
I/Corona ( 9276): “response”:"[]",
I/Corona ( 9276): “responseHeaders”:{
I/Corona ( 9276): “Connection”:“Keep-Alive”,
I/Corona ( 9276): “Content-Length”:“2”,
I/Corona ( 9276): “X-Android-Response-Source”:“NETWORK 200”,
I/Corona ( 9276): “Date”:“Sun, 17 Jul 2016 22:26:23 GMT”,
I/Corona ( 9276): “X-Android-Sent-Millis”:“1468794376204”,
I/Corona ( 9276): “X-Android-Received-Millis”:“1468794376261”,
I/Corona ( 9276): “X-Android-Selected-Transport”:“http/1.1”,
I/Corona ( 9276): “Keep-Alive”:“timeout=5, max=100”,
I/Corona ( 9276): “X-Powered-By”:“PHP/5.5.9-1ubuntu4.14”,
I/Corona ( 9276): “Content-Type”:“text/html”,
I/Corona ( 9276): “HTTP-STATUS-LINE”:“HTTP/1.1 200 OK”,
I/Corona ( 9276): “Server”:“Apache/2.4.7 (Ubuntu)”
I/Corona ( 9276): },
I/Corona ( 9276): “responseType”:“text”,
I/Corona ( 9276): “status”:200,
I/Corona ( 9276): “url”:"http://107.170.34.199/barber_search_script.php",
I/Corona ( 9276): “isError”:false
I/Corona ( 9276): }
I/Corona ( 9276): Upload complete!
I/Corona ( 9276): []
Can you print the value of the URL you’re calling? I just tried to hand build the URL using my local latitude and longitude and I got [] back. It’s possible you’re URL you’re actually using in your app is not returning any values from the script.
Did you mean to just do print(URL)? which was:
URL = “http://107.170.34.199/barber_search_script.php?” … “currentLat=” … currentLocation.latitude … “¤tLng=” … currentLocation.longitude
it prints:
nil
local URL = "http://107.170.34.199/barber\_search\_script.php?" .. "currentLat=" .. currentLocation.latitude .. "¤tLng=" .. currentLocation.longitude print( URL ) network.request( URL, "GET", networkListener, params)
tried that, nothing comes out in the console
Can you post your current function handling your network request?
local function testEvent(event) local phase = event.phase if phase == "ended" then --params.body = "currentLat=" .. currentLocation.latitude .. "¤tLng=" .. currentLocation.longitude local URL = "http://107.170.34.199/barber\_search\_script.php?" .. "currentLat=" .. currentLocation.latitude .. "¤tLng=" .. currentLocation.longitude print(URL) network.request( URL, "GET", networkListener, params) return true end end
local function networkListener( event ) print( json.prettify( event ) ) if ( event.isError ) then print( "Network error: ", event.response ) else print ( "Success!" ) myTable = json.decode(event.response) print(event.response) print(myTable[1].distance) end end
Can you change the print(URL) to print(“URL:”, URL, “*****”)
It can’t be nil or an empty string.
local function testEvent(event) local phase = event.phase if phase == "ended" then --params.body = "currentLat=" .. currentLocation.latitude .. "¤tLng=" .. currentLocation.longitude local URL = "http://107.170.34.199/barber\_search\_script.php?" .. "currentLat=" .. currentLocation.latitude .. "¤tLng=" .. currentLocation.longitude print("URL:", URL, "\*\*\*\*\*") network.request( URL, "GET", networkListener, params) return true end end
console now doesnt output anything, i also moved the print event.response to be after print myTable[1].barberid in the network listener, so now not even the empty ’ [] ’ are being shown
local function networkListener( event ) print( json.prettify( event ) ) if ( event.isError ) then print( "Network error: ", event.response ) else print ( "Success!" ) myTable = json.decode(event.response) print(myTable[1].distance) print(event.response) print(myTable[1].barberid) end end
You have to be getting some thing printed for the URL line. You don’t need to test this part on a device. Your Corona console log in the simulator should be sufficient to see these print statements.
Rob
the network request takes currentLocation in the URL, which are only defined if myMap is true, which it isnt in the simulator
You dont have a variable named “debug” do you?
i dont!
This line: print(“URL:”, URL, “*****”)
has to be outputting something unless there are runtime errors just before it. Can you post your build.settings?
Do you have something like this: showRuntimeErrors = false,
in your config.lua or do you have something like:
Runtime:addEventListener( “unhandledError”, myUnhandledErrorListener )
in your code anywhere?
I agree, this has been giving me a headache all day. I really dont understand why its not outputting anything at all in the console, and i dont see any runtime erros before it.
build.settings:
settings = { iphone = { plist= { UIBackgroundModes = {"remote-notification"}, UIApplicationExitsOnSuspend = false, NSLocationWhenInUseUsageDescription = "We need location services in order to specify appointment locations!", UIPrerenderedIcon = true, UIStatusBarHidden = false, NSAppTransportSecurity = { NSExceptionDomains = { NSAllowsArbitraryLoads = true, ["coronalabs.com"] = { NSIncludesSubdomains = true, NSThirdPartyExceptionAllowsInsecureHTTPLoads = true }, ["youtube.com"] = { NSIncludesSubdomains = true, NSThirdPartyExceptionAllowsInsecureHTTPLoads = true }, ["google.com"] = { NSIncludesSubdomains = true, NSThirdPartyExceptionAllowsInsecureHTTPLoads = true }, }, }, }, }, orientation = { default = "portrait", supported = { "portait", "portraitUpsideDown", }, }, 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 }, }, }, plugins = { ["plugin.OneSignal"] = { publisherId = "com.onesignal", }, ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true, ["android-kindle"]=true }, }, }, }
and no to the rest of the questions!
So apparently I had a function that i forgot to delete in my code that was interfering with the testEvent, I now got it to print the URL, but when i try to print myTable[1].barberid nothing is output. Heres the output from json.prettify:
I/Corona (12244): URL: *****
I/Corona (12244): {
I/Corona (12244): “bytesEstimated”:-1,
I/Corona (12244): “bytesTransferred”:163,
I/Corona (12244): “name”:“networkRequest”,
I/Corona (12244): “phase”:“ended”,
I/Corona (12244): “requestId”:"<type ‘userdata’ is not supported by JSON.>",
I/Corona (12244): “response”:"{“1”:{“barberid”:“2”,“distance”:“0.05304842361994396”},“2”:{“barberid”:“5”,“distance”:“0.05304842361994396”},“3”:{“barberid”:“6”,“distance”:“0.05304842361994396”}}",
I/Corona (12244): “responseHeaders”:{
I/Corona (12244): “Connection”:“Keep-Alive”,
I/Corona (12244): “Content-Type”:“text/html”,
I/Corona (12244): “X-Android-Response-Source”:“NETWORK 200”,
I/Corona (12244): “Date”:“Mon, 18 Jul 2016 18:10:06 GMT”,
I/Corona (12244): “X-Android-Sent-Millis”:“1468865405753”,
I/Corona (12244): “X-Android-Received-Millis”:“1468865405811”,
I/Corona (12244): “X-Android-Selected-Transport”:“http/1.1”,
I/Corona (12244): “Keep-Alive”:“timeout=5, max=100”,
I/Corona (12244): “X-Powered-By”:“PHP/5.5.9-1ubuntu4.14”,
I/Corona (12244): “Vary”:“Accept-Encoding”,
I/Corona (12244): “HTTP-STATUS-LINE”:“HTTP/1.1 200 OK”,
I/Corona (12244): “Server”:“Apache/2.4.7 (Ubuntu)”
I/Corona (12244): },
I/Corona (12244): “responseType”:“text”,
I/Corona (12244): “status”:200,
I/Corona (12244): “url”:"http://107.170.34.199/barber_search_script.php?currentLat=25.9901778¤tLng=-80.3572953",
I/Corona (12244): “isError”:false
I/Corona (12244): }
I/Corona (12244): Success!
I/Corona (12244): {“1”:{“barberid”:“2”,“distance”:“0.05304842361994396”},“2”:{“barberid”:“5”,“distance”:“0.05304842361994396”},“3”:{“barberid”:“6”,“distance”:“0.05304842361994396”}}
last line is the output of print(event.response)
Your data is now basically:
myTable[1].barberid = 2
myTable[1].distance = 0.05304
myTable[2].barberid = 5
myTable[2].distance = 0.05304
myTable[3].barberid = 6
myTable[3].distance = 0.05304
That’s what i thought too, but print(myTable[1].barberid) isnt outputting anything in the console.
Try changing your PHP script from:
echo json\_encode($barbers);
to
echo json\_encode($barbers, JSON\_NUMERIC\_CHECK );
Your numeric array keys ($q) is being converted to a string and so are other number items. Try that and see if it behaves better.
Rob
Tried that, still isn’t printing anything to the console