User Tools

Site Tools



Probably the most important part of coding is “debugging”. The strict definition of this might be removing problems or mistakes in your code, but it is more about being able to see what your code is doing, and finding the problems. When working with Layar you have several stages that you can debug at.

  1. Syntax problems while coding.
  2. Forming of JSON response by server.
  3. Structure of JSON response.
  4. Interpretation of JSON response.
  5. Actual appearance in app.

You'll notice a lot of reference to JSON. That is is the structure that Layar uses to pass information from your server to the app.

1. Syntax Problems While Coding

The easiest source of mistakes are typos - missing semi-colons, stray quote marks, misspelled variable names etc. You're life will be considerable easier if you use a code editor that checks those things for you. Notepad++ will highlight syntax to make it easier to read, but something like Eclipse PDT will actually flag errors. NetBeans is also an option.

4. Interpretation of JSON Response

Why is this one out of sequence? Because you need to do this stage in order to do the two below.

In the “My Layers” area on the Layar publishing site, you will see buttons to test your layers. Clicking on the button will take you to a page that includes a Google map. Directly underneath the map you can enter a geolocation (city name, post code etc.) or switch to entering coordinates. Go to the location where your hotspots should be, and click on the “Load POIs” button over to the right.

If all goes well you should see some pins on the map for your hotspots. If not, then check the Console underneath the map for errors.

The console area will include a “POI fwd url”. This is the URL that you will need for stage 2. If you copy and paste the whole thing into a web browser (starting at the http, and normally ending with accuracy=100), then it will provide all of the parameters that an app would send (location coordinates, uid etc.) This is vital to properly test your system.

I think that the userId is standard, and is just the 'test user', but I've masked it just in case.

Other things to check are in the POI List over towards the bottom right. This will list each of the hotspots returned, including any parameters that you have set for them (transformations etc). Any images or 3D models will be included, and you can click on the links to check that they are pointing to the right locations (open them in a new tab/window so that you don't loose the testing page).

2. Forming of JSON Response by Server

Once the files have been uploaded to your server, then you can visit the page in a web-browser and see what you get. Problems accessing the database, infinite loops, array indices out of bounds, not initialising variables etc. will show up here. Hopefully the message that you get will be meaningful enough to help you solve the problem. Most often you will be given a line number where the error occurred - which is even more reason to use a development tool, because it will number your lines.

Note you will need the string of parameters provided in the step above.

3. Structure of JSON Response

Even if your server presents some text without any errors, it could still include mistakes. JSON is very particular about how information is structured, and it is very easy to have a comma missing and invalidate the whole thing.

To test for this, copy and paste the text presented by the server into a “JSON validator”. I commonly use JSONLint, but the JSON Formatter is also very good. Do a web-search, there are plenty of options.

Hopefully if there are any errors they will be pointed out to you, and you can go back to your code to fix them.

In this case, the value for longitude is missing. The value for latitude also looks incorrect, so you can tell that something had gone badly wrong there.

5. Actual Appearance in App

So you've managed to perfectly form some JSON, and the Layar site recognises all of your hotspots? Now it's time to try it in the app. Of course, you probably tried it in the app first, ran into a problem, and then went back through the rest - that's normal.

Hopefully at this point everything looks fine, but if not there are a few things to try:

  • Have a look a the list view; is everything listed that you expected?
  • Maybe your hotspots are in the right place, but the phone thinks you are somewhere else. Have a look at the map; does it show you in the right place?
  • Are you indoors? Not only will the phone have a hard time finding your position from GPS signals, but metal/magnetic sources in the environment might be messing around with your compass.
  • If points appear in the list/map and are nearby, but you can't see them, then try looking up/down - the altitude might be off.
  • Scale might also be an issue (too small to see, or so big that they're being clipped).
  • If you are using images, then check that they are set to face you. Maybe you're just seeing them side-on.
layarmmo-debug.txt · Last modified: 2012/11/07 17:05 by matthewleach