App That Uses Maps API

local URL = "http://107.170.34.199/barber\_search\_script.php?" .. "currentLat=" .. currentLocation.latitude .. "&currentLng=" .. 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 .. "&currentLng=" .. currentLocation.longitude local URL = "http://107.170.34.199/barber\_search\_script.php?" .. "currentLat=" .. currentLocation.latitude .. "&currentLng=" .. 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 .. "&currentLng=" .. currentLocation.longitude local URL = "http://107.170.34.199/barber\_search\_script.php?" .. "currentLat=" .. currentLocation.latitude .. "&currentLng=" .. 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&currentLng=-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

What is being printed to the console now?

I/Corona  (21742): {
I/Corona  (21742):   “bytesEstimated”:-1,
I/Corona  (21742):   “bytesTransferred”:148,
I/Corona  (21742):   “name”:“networkRequest”,
I/Corona  (21742):   “phase”:“ended”,
I/Corona  (21742):   “requestId”:"<type ‘userdata’ is not supported by JSON.>",
I/Corona  (21742):   “response”:"{“1”:{“barberid”:2,“distance”:0.0043117895569319},“2”:{“barberid”:5,“distance”:0.0043117895569319},“3”:{“barberid”:6,“distance”:0.0043117895569319}}",
I/Corona  (21742):   “responseHeaders”:{
I/Corona  (21742):     “Connection”:“Keep-Alive”,
I/Corona  (21742):     “Content-Type”:“text/html”,
I/Corona  (21742):     “X-Android-Response-Source”:“NETWORK 200”,
I/Corona  (21742):     “Date”:“Tue, 19 Jul 2016 19:27:51 GMT”,
I/Corona  (21742):     “X-Android-Sent-Millis”:“1468956470146”,
I/Corona  (21742):     “X-Android-Received-Millis”:“1468956470219”,
I/Corona  (21742):     “X-Android-Selected-Transport”:“http/1.1”,
I/Corona  (21742):     “Keep-Alive”:“timeout=5, max=100”,
I/Corona  (21742):     “X-Powered-By”:“PHP/5.5.9-1ubuntu4.14”,
I/Corona  (21742):     “Vary”:“Accept-Encoding”,
I/Corona  (21742):     “HTTP-STATUS-LINE”:“HTTP/1.1 200 OK”,
I/Corona  (21742):     “Server”:“Apache/2.4.7 (Ubuntu)”
I/Corona  (21742):   },
I/Corona  (21742):   “responseType”:“text”,
I/Corona  (21742):   “status”:200,
I/Corona  (21742):   “url”:"http://107.170.34.199/barber_search_script.php?currentLat=25.9907928&currentLng=-80.3568651",
I/Corona  (21742):   “isError”:false
I/Corona  (21742): }
I/Corona  (21742): Success!
I/Corona  (21742): {“1”:{“barberid”:2,“distance”:0.0043117895569319},“2”:{“barberid”:5,“distance”:0.0043117895569319},“3”:{“barberid”:6,“distance”:0.0043117895569319}}

networkListener:

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].barberid) end end

I even tried changing the php script to fetch_row instead of fetch_assoc, still nothing. (right now its back to fetc_assoc)

The keys are strings, not numbers which is weird. But it id convert the id and distance to numbers correctly.