I want to develop an Android application. I'm still a newbie here.

What I want is to develop my app just like a GIS that can implement reverse geocoding. So I can put in lat / lon coordinates and then text is returned, for example the city name.

But I don't want to implement Reverse Geocode using Geocoder from Google, all I want is for the coordinates that I entered to be checked from a shapefile (.shp) in the database, then return a city name. And I want to use MySQL as a database for my shapefile (shp). Is it possible, and what should I do to make it happen? Could you give a tutorial?

Thanks in advance.

  • So, all you want is determining which polygon your coordinate lies in? I wouldn't call that reverse geocoding. – Uffe Kousgaard Apr 11 '12 at 7:50
  • Yes, that's what I mean. I want my app is able to get where my coordinate is, and determining which polygon is. It's because I want to build my own polygon that be able to catch the coordinate that I gave. So, even the outcomes is still city name or district, I want that comes from the polygon that I made before exactly as what I want. If it is not reverse geocode, what should I call it? And how can I implement this? Thanks Uffe – AdityaSetyadi Apr 11 '12 at 19:20

Seeing as it's Android, you might be far better using something like Spatialite, which has an active project building on Android. Spatialite can store all your city point co-ordinates (and even your city boundaries)

So long as you don't need absolute pinpoint accuracy, then a possible approach is to find the nearest "city point" to your point (the more city points you have the more accurate it will be). This is fairly easy to do in Spatialite, and is very quick if you use an index. This is what is known as "reverse geocoding" not your approach comparing a point to an entire shape, as Uffe has pointed out. It would be possible to return which city polygon a point is within in Spatialite, but this would take far longer, and may be too slow for the Android platform, depending on your dataset size.

If you are doing all this on a server, not the device, then obviously your options are much greater and you can use many other solutions, although I would say PostGIS could be the most effective.

  • Alright, I know my opinion is completely wrong and impossible. Sorry. I just want to ask, is it possible or not, because I really want to implement that. It's not only I'd already have a shapefile that actually made a section as a polygon with a name in each section, that's also I think it will be more accurate than if we implement from someone else is build. Furthermore, if I can do it, It will be more effective if we implement it in a small city that we don't know exactly where it is, we can build the polygon as what we want and also with accurate information from there. But Thanks Stev_k – AdityaSetyadi Apr 11 '12 at 19:58
  • as I said, it's possible. Look into spatialite and the Contains functon, or ST_Contains. As in, "select * from my_polygons where Contains(mypoint,my_polygons.geometry" or similar. There is a section at gaia-gis.it/gaia-sins/spatialite-cookbook/html/pop-places.html which may help – Stev_k Apr 11 '12 at 22:37
  • I try to read it, but unfortunately I didn't understand where I have to take the first step. Sorry. Can you give me the tutorial from the begin. Thanks Stev_k – AdityaSetyadi Apr 12 '12 at 11:33
  • go to "Table of Contents" – Stev_k Apr 12 '12 at 11:53
  • Ok, I'll try. But is it possible if we use MySQL instead of SQLite? – AdityaSetyadi Apr 12 '12 at 12:44

I'm not a programmer, but it sounds to me like using shapefiles is just going to make it more difficult. Why not just store city coordinates in a table then compare them with those that are entered? How are you going to deal with coordinates that aren't within a city?


You can take the GIS approach and use one of the other suggestions (spatialite etc) or use a more simple approach: Use standard SQL to calculate the distance to the nearest city coordinate and if the distance is below some threshold, you know which city you are in. Assuming it isn't critical if you are just inside or outside the actual city boundary. You may need several coordinates to describe the city (larger city > more coordinates).

  • Where I have to begin? I judt dont know any single thing. Sorry. – AdityaSetyadi Apr 12 '12 at 11:43
  • If you don't know anything, you should start in school. Sorry, but you can't expect to get the whole problem solved here. Some basic knowledge is expected in advance. – Uffe Kousgaard Apr 12 '12 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.