3

So in my app I am making use of google map apis and I'm using Geocoding to determine the Address based on the user's current location. I was using the Geocoder Android Class but I've found that it truly works terribly. It's just not reliable. So I used a post I saw here at SO to create my own Geocoder. Problem is, I now don't know if I'm using server side or client side geocoding. This is kind of important because one has a limit and the other really doesn't. All of my code is in Android though.

Here's some code, this is within my "MyGeocoder" Class:

public List<Address> getFromLocation(double latitude, double longitude,
        int maxResults) throws IOException, LimitExceededException {
    if (latitude < -90.0 || latitude > 90.0) {
        throw new IllegalArgumentException("latitude == " + latitude);
    }
    if (longitude < -180.0 || longitude > 180.0) {
        throw new IllegalArgumentException("longitude == " + longitude);
    }

    if (isLimitExceeded(context)) {
        throw new LimitExceededException();
    }

    final List<Address> results = new ArrayList<Address>();

    final StringBuilder url = new StringBuilder(
            "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&latlng=");
    url.append(latitude);
    url.append(',');
    url.append(longitude);
    url.append("&language=");
    url.append(Locale.getDefault().getLanguage());

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url.toString());

    try {
        HttpResponse response = httpclient.execute(httppost);
        String jsonResult = inputStreamToString(
                response.getEntity().getContent()).toString();

        Gson gson = new Gson();
        MyGeocodeResponse geocodeResponse = gson.fromJson(jsonResult, MyGeocodeResponse.class);
        final Address current = new Address(Locale.getDefault());
        if(geocodeResponse.getStatus().equals(STATUS_OK)) {
            MyGeocode locGeocode= geocodeResponse.getResults().get(0);
            String streetAddress = "";
            for(MyAddressComponent component : locGeocode.getAddress_components()) {
                for(String type : component.getTypes()) {
                    if(type.equals("locality")) {
                        current.setLocality(component.getLong_name());
                    }

                    if(type.equals("administrative_area_level_1")) {
                        current.setAdminArea(component.getLong_name());
                    }

                    if(type.equals("street_number")) {
                        if(streetAddress.length() != 0) {
                            current.setAddressLine(0, component.getLong_name() + " " + streetAddress);
                        } else {
                            streetAddress = component.getLong_name();
                        }
                    }

                    if(type.equals("route")) {
                        if(streetAddress.length() != 0) {
                            current.setAddressLine(0, streetAddress + " " + component.getShort_name());
                        } else {
                            streetAddress = component.getShort_name();
                        }
                    }
                }
            }   
            current.setLatitude(latitude);
            current.setLongitude(longitude);
            results.add(current);
        }


        Log.i("TEST", "Got it");

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return results;
}

Edit: And I guess a further questions is, if this is server-side Geocoding, then can this code only be run 2,500 times per day period, or can it be run 2,500 times daily per user of the app? If it's the first option I'm still ok, but if it's the 2nd option I don't see how any app that wants to have a half-way big user base can use server-side geocoding without hitting that limit.

user1513171
  • 1,912
  • 6
  • 32
  • 54

1 Answers1

1

I now don't know if I'm using server side or client side geocoding

after looking to your code you wrote http://maps.googleapis.com/maps/api/geocode/json?sensor=true&latlng=,so it is server side reverse geocoding as you are calling geocoding api by making an extra External http call.

if this is server-side Geocoding, then can this code only be run 2,500 times per day period, or can it be run 2,500 times daily per user of the app?

2,500 request limit is per IP address(basically it is mentioning 2500 request per day),yah this code only be run 2,500 times per day for all of your user.One thing you should keep in mind you are making http call to geocoder api so it doesn't matter from where you are making this call from server or from client.

you should have a look on this google link where they have mention "When to Use Client-Side Geocoding" and "When to Use Server-Side Geocoding".

Dev
  • 2,326
  • 24
  • 45
  • So, @user3523641, if my app calls this every time someone opens my app, then will this code only work 2,500 times in a day? Or will it work 2,500 times per user? Since it's IP address based... Keep in mind this is called from my Android app code, not on a server of mine. – user1513171 Jun 21 '14 at 00:42
  • Sorry for late reply, yes I was in same confusion so I asked this question to good channel partner, they answer me that either you use form mobile or from Web clients server it remain same, I was confused with this answers as it doesn't give any clarity so I have asked this question to google developer team let's see what they have to say – Dev Jun 25 '14 at 18:49
  • Mean when you should go with android . location. Geocoder which has no limit visit below link for more detail http://stackoverflow.com/questions/24186388/google-maps-mobile-sdk-for-business-vs-google-maps-android-api/24189953#24189953 – Dev Jun 25 '14 at 18:56