views:

1572

answers:

2

I'm trying to find the best way of parsing the response from a "normal" (i.e. not using the API) Google Maps page in my java code.

Reason: I want to submit a query string requesting a listing (be it hotels, restaurants etc.) and then parse the JSON that comes back. I had looked into using the Google Maps API, but it doesn't seem to cover what I want to do, as this type of URL:

http://maps.google.de/maps/geo?q=address&output=xml&oe=utf8&sensor=false&key=...

is OK but this isn't:

http://maps.google.de/maps/geo?q=address+hotels&output=xml&oe=utf8&sensor=false&key=...

(due to the "+hotels" term). So I think the only option is to use a google maps response e.g.

http://maps.google.de/maps?q=address+hotels

and parse the JSON information that is included at the end. Does anyone have some hints as to how best accomplish this?

+2  A: 

You should first make absolutely sure that the API doesn't support what you need. Checking the docs and maybe even reaching a real Googler might pay off. It strikes me as odd that their API wouldn't support something as simple as adding in another term.

If you're forced to do it the "hard way", there are two main steps:

1) Find and learn a JSON parsing library for Java. I can recommend Jackson -- fast, sturdy, and just released a version 1.0.0.

2) Teach your code to understand the spec the Google uses in their response. This is by far the most challenging part. My apologies, but I know nothing about Google's spec in this area. If you can find official docs, that's best. Or find unofficial docs published by someone else who had to do similar work. Otherwise, you may have to "reverse engineer".

dirtyvagabond
+2  A: 

Re. the google api docs: it does seem that what you're trying to do goes against the intention of Google to make their product (= a map) available to you, the developer, for your custom enhancement (by adding business outlet information or whatever). There's plenty of stuff on the Google maps API site describing this. But to parse their data (coming out of their database) and to display it independently of their product would seem to be rather different: section 10.12 of the terms explicitly cover this:

...code.google.com/intl/de/apis/maps/terms.html

However, there are apps out there (the "Around Me" iPhone app, for example) that seem to do just that: there might be a special arrangement between Google and Apple in that regard.

EDIT: alternatively you could look at this problem another way and use the Google Base API feed, since this allows you to build query strings specifying resource, distance, location etc. - i.e. it returns the data you require without using the Maps API (which you don't need anyway, given your description).

davek