Monday, February 16, 2009

I just spent the last twelve hours hacking on my Android app, Tag Your World. I made some progress but the code is still pretty bad (whaddya' expect? It's still my first Java program!).

Most of the morning was spent figuring out how to parse a JSON-formatted KML response from Google's Maps API. After looking at various XML parsers, most notably SAX, I decided I might as well just do it manually.

By "manually" I mean I took the JSON string, converted it into a JSONObject and looped through the keys. When I found the "Placemarks" key, which holds several addresses of different resolutions (address level, street level, etc.), I converted that to a JSONArray and passed it off to a function which populated an instance variable ("my first use of polymorphism!" he says proudly).

Overall, I went from a JSON string -> JSONObect -> JSONArray -> JSONObject just to fetch the first address line in the KML. There's got to be a better way! I find it hard to believe that there's no easy way to take a KML-encoded string and magically produce a Java object. Unless I'm on the bleeding edge and I don't know it.

Spent the evening doing some cleanup work (the TimePicker wasn't handling hours properly) and adding a few cute features (Satellite View v Map View).

The next major thing I need to do is to integrate the Android app with my AppEngine app to show them both off at the next NYC Cloud Computing Meetup on the 26th and the next NYC Android Developer Meetup, whenever that will be.

On top of that, I've got two day-long job interviews this week! For someone who hasn't had any work for awhile, I'm awfully busy!

1 comment:

  1. If you used the XML variant rather that JSON, you could use an XPath expression to quickly extract the piece you want. While I'm no apologist for XML - often I think it's bloated, nasty overkill at best - XPath is a fairly good thing.

    There's JSONPath, similar to XPath, but I'm not sure how widely supported it is. XPath has more legs and has been around longer.

    Just thought this might help, if what you need from XML is fairly small. If you need a full object representation of multiple elements and attributes, a full XML mapping tool might be useful - Castor is my favorite, and XmlBeans isn't bad. If you can use those in Android; not sure what they have.

    But I'd aim for XPath first.