Parse JSON response from Google Maps page - java

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?

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".

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).

Related

When do new things get added to the Java API

I have been wondering about this for a while and I can’t really find a clear answer. You see the standard Java API is really big and it includes a lot of different libraries and classes for you to use from GUI design to sending data over the Internet to basic things like sending a String to the console.
It also includes things like reading MIDI generating secure random Strings, things that seem really specific. But at the same time there doesn’t seem to be any standard JSON libraries available while JSON is an universal way of sending data between systems.
So what I want to know is: When does something get added to the Java API? What does something need to be considered to be added to the API?
There is a "framework" that drives how new features "get" into java; to manifest themselves later on as new language elements or libraries.
Enter ... the Java Community Process!
Meaning: this is a forum where people make suggestions; which then get discussed; and at some point are either "added to Java somehow"; or rejected.
And for starters: the JSON-P project about a JSON processing API was/is driven by the jcp, see entry 374.
Finally: but you are correct, not everything that shows up in the "standard library" should be there; whereas other important parts take way too long before people can agree on a proposal. And of course, there is also a long history of evolution.
So: when you could restart Java from scratch; you would organize things in a different way (and to a certain degree, that is what Java9 is trying to enable with the new module concept).

Evernote: Get a list of all edits

I am trying to develop a simple statistics tool to analyse various behaviours of collaborators within an Evernote Notebook using the Evernote Java API.
I need the informations which user edited which note and when.
Even though the documentation is quite good, I am still unable to find the required functionality inside the api.
(TLDR:)
Is there a way to access a list of edits of a evernote note using the API?
I am not bound to using the Java SDK so if there is a way, which is limited to using another language, it would be no problem to switch.
Andreas - Did you look into these methods in the API?
NoteStore.GetNote and NoteStore.getNoteApplicationData
It sounds like this would be a decent place to start at the very least. I cannot say for certain if this will return everything you are looking for though.
I hope this helps!
I'm not exactly sure what you are looking for but NoteStore#listNoteVersions might be the one you want. You can get a list of NoteVersionId and then use another API called NoteStore#getNoteVersion to get metadata to see which note is updated when.
Note that the API is probably only for premium accounts.

How to use google place API in android app effectively

There are multiple options to use with AutoCompleteTextView,
calling api to server and let server control suggesting auto complete places proxying google APIs, considering control to throttle the rate
calling directly from client to google API on raw rest API and parsing response JSON
is there a Java client for google place API already available that abstracts parsing and other parts and respects current location to add context to what user might be looking for and other contextual data about user to fine tune search ? if so an example would be great pointer
what is the common practice around here
To answer your last question, I have developed both a pure Java client for the Google Places API (Sprockets for Java) and an Android library project (Sprockets for Android) that builds on top and provides classes like GooglePlaceAutoComplete and GooglePlacesLoader.
After setting up the library, adding a GooglePlaceAutoComplete widget to your app is just a single tag in a layout (example below). In your Activity or Fragment, you can also register an OnPlaceClickListener that is called when the user chooses a suggested place.
<net.sf.sprockets.widget.GooglePlaceAutoComplete
android:id="#+id/place"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Sounds like you need some documentation to make decisions. A good place to start is, of course, the google places api for android section. I think you will find here all the info you need.
calling api to server and let server control suggesting auto complete
places proxying google APIs, considering control to throttle the rate
calling directly from client to google API on raw rest API and parsing
response JSON
I would go for the the first option if I would have an application that will need some limitations of request and data gathering about maybe who/where/when your requests are made, this being(I think) the best solution to control your billing and keep yourself the track of requests. The second solution it is not bad either, but keep in mind that you will enconde your google places api key in your application! More about the billing and usage limitations here.
is there a Java client for google place API already available that
abstracts parsing and other parts and respects current location to add
context to what user might be looking for and other contextual data
about user to fine tune search ? if so an example would be great
pointer
On the same website you will find samples of how to use google places api in your applications. For autocomplete check this out.

How do I use Google Maps API in a Java code to fetch coordinates of specified location?

In a BI project I'm currently working on, we are in need of geo-coordinates for a list of locations. With the address location (such as "New York, US") as input, the output should be the coordinates as a latitude-longitude pair (like {40.71435, -74.00597}). The behaviour is similar to what is seen on this page.
A similar question earlier on SO points to using the Google Maps API in JavaScript to achieve this, but I'm looking for a Java solution -- some function of the form getCoordinates(location), because this is a small requirement in a larger Java program already in existence.
Any pointers on how I may use the Google Maps API (or any other maps API) in Java to achieve this would be of great help!
You can use the Google Geocoding HTTP API (see here).
To connect to it and get the responses you can use a Java URLConnection (tutorial is here) and parse the response using your favourite Json library (I personally use Jackson)
So you'd like a way to perform Google Maps API Geocoding via Java - here's one that might work for you. The response might not be in the exact same format you need but should be pretty workable:
http://code.google.com/p/geocoder-java/
You can see the final format returned in LatLng.java - just trace the code through starting from GeocodeResponse.java and you'll see the final format - the classes are pretty simple.

Automatic sitemap generation

We have recently installed a Google Search Appliance in order to power our internal search (via the Java API), and all seems to be well, however I have a question regarding 'automatic' site-map generation that I'm hoping you guys may know the answer to.
We are aware of the GSA's ability to auto-generate site maps for each of its collections, however this process is rather manual, and considering that we have around 10 regional sites that need to be updated as often as possible, its not ideal to have to log into the admin interface on a regular basis in order to export them to the site root where search engines can find them.
Unfortunately there doesn't seem to be any API support for this, at least none that I can find, so I was wondering if anyone had any ideas for a solution/workaround or, if all else fails, the best alternative.
At present I'm thinking that if we can get the full index back from the API in the form of a list, then we can write an XML file out using that the old fashioned way using a chronjob or similar, however this seems like a bit of a clumsy solution - any better ideas.
You could try the GSA Admin Toolkit, or simply write some code yourself which just logs in on the administration page and then uses that session to invoke the sitemap export URL (which is basically what the Admin Toolkit does).

Categories