2

I'm designing an android app which must categorise user input based on their location and assign it to the appropriate folder based on the city the user is in. This is trivial when the user is within a large city. The problem arises when the user is in a village or town which will not have its own category in my app. In this case, the user input must be assigned to the nearest large city with 100000 or more residents. I have managed to obtain the user's coordinates so far. I use the following code to obtain the user's city.

List<Address> list = geoCoder.getFromLocation(location
                .getLatitude(), location.getLongitude(), 1);
        if (list != null & list.size() > 0) {
            Address address = list.get(0);
            result = address.getLocality();
            return result;

This code is not suitable as it returns names of towns and villages as well. What I need to do is to find the nearest city to the given coordinates which has more than 100 000 inhabitants and assign this city to my user input, rather than the village or town in which the user is in. I am looking for suggestions on how this can be done.

Alk
  • 5,215
  • 8
  • 47
  • 116
  • There are some options here: http://stackoverflow.com/questions/6159074/given-the-lat-long-coordinates-how-can-we-find-out-the-city-country – schweerelos Feb 22 '16 at 03:19
  • I downloaded the cities15000.tsv file. I could upload this to my online sql database, however the problem is that the file is over 5MB which is the upload limit there. Is there a way I could query this file to remove all cities below 50k to decrease the file size? I tried looking up tsv querying however I wasn't able to find anything useful to this issue. – Alk Feb 22 '16 at 03:28
  • I don't actually know anything about the options in the answer I linked. Perhaps you'd be better off using a service hosted elsewhere, eg http://wiki.openstreetmap.org/wiki/Nominatim#Reverse_Geocoding mentioned in one of the other answers to that question? – schweerelos Feb 22 '16 at 03:49
  • Sorry, Nominatim probably has the same issue as you ran into with Google geocoder. Perhaps this one -- though it still uses smaller cities than you want: http://www.geonames.org/export/web-services.html#findNearbyPlaceName or findNearby / extended findNearby – schweerelos Feb 22 '16 at 03:52
  • go here and download cities which is a 4.6 meg csv file == http://www.opengeocode.org/download.php – Tasos Feb 22 '16 at 04:15
  • or zip the other one you have to make the size smaller so you can upload it – Tasos Feb 22 '16 at 04:23

0 Answers0