Search code examples
javagoogle-app-enginegoogle-geocoder

Geocoder API for Java


I'm trying to use the Geocoder API for java located at: http://code.google.com/p/geocoder-java/

These are the lines of code I've written, and it works perfectly when I run it as a GAE web application.

    final Geocoder geocoder = new Geocoder();
    GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(req.getParameter("location").toString()).setLanguage("en").getGeocoderRequest();
    GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
    List<GeocoderResult> someList = geocoderResponse.getResults();
    GeocoderResult data = someList.get(0);
    GeocoderGeometry data_2 = data.getGeometry();
    BigDecimal Latitude = data_2.getLocation().getLat();
    BigDecimal Longitude = data_2.getLocation().getLng();

What it does is that I give in a text, for example new york, and it finds out the longitude and the latitude of that area.

However, when I put the same lines of code into the GAE, sometimes when I run this code, I get check bounds exception located at "GeocoderResult data = someList.get(0)";

Sometimes I don't get the error and it displays the coordinates on the webpage correctly. So I'm a bit confused, on the website, it shows that it supports GAE, or is there something wrong with the geocoder provided by google itself has some problem?

Usually it doesn't work during afternoon or midnight at eastern time.


Solution

  • I believe you are hitting API limits here. The API rate limits are set per IP Address and infrastructures such as Google App Engine commonly use a shared IP to make the request to the server, hence while your application per se does not hit those limits, because of the shared infrastructure, it probably hits those limits and you do not get any results.