Is there any existing Java library that allows you to do fast, in-memory lookups of zipcodes (bonus, state and city) from latitude/longitude?
Asked Answered
V

1

6

I have seen many so-called "reverse geocoding" libraries in various languages; all depend on calling an external provider via REST or some similar method. However, you cannot call a REST provider if you must handle thousands of requests per second.

On the other hand, the problem should be simple to solve - CSV-based databases are available for free with this information. The issue is the time and cost of writing an efficient and well-tested in-memory search implementation, versus downloading or buying an existing one.

I can't find any after a lot of looking, but I can't believe there can't be one. Is there any pre-written library that does this?

This question:

Fastest way to find the location(zip, city, state) given latitude/longitude

came the closest, but essentially indicates how to write the solution, not that there is anything available off the shelf. But there must be some library everyone uses for this. A dozen people a day must have this problem.

Viscometer answered 19/4, 2012 at 20:31 Comment(1)
@birryree, comments are for comments. If you want to bookmark the question, the use the favorite question feature (click the star).Tarahtaran
S
3

Spatial databases (e.g. Postgresql with PostGis) use algorithms which are fast in looking up data for given latitude/longitude information. As you want to use a Java library and have it in memory you could look at the H2 Spatial database. I have never used it, so I can't comment on its performance.

Edit: Hm, looking closer at the link I've provided shows that this is a planned feature... Personally I'd simply use Postgresql/PostGis (with or without Java as server frontend) and be done with it. If your server has enough memory it will still fit the "in-memory" requirement. Naturally it does not fit the Java library requirement. There is however JSI, which could be used in memory and with Java.

Slant answered 19/4, 2012 at 20:52 Comment(3)
Setting up and maintaining postgres just to solve this problem would be impossible in my situation. :( JSI looks quite promising! What everyone has are freely available lists of ZIP/city/state/etc. with their lat/long coordinates, rather than rectangles, so point-to-point rather than point-to-rectangle searching is not really appropriate. It may be adaptable... but still... having to adapt such a thing, making thousands of tiny rectangles? Is there really no prepackaged solution available on the market? I am astounded that neither I (nor apparently anyone else) can find one.Viscometer
Well, the JSI library works perfectly well with points, just use a rectangle of zero size (i.e. set minY=maxY and minX=maxX). In fact it was originally intended to add 'native' support for points, but the performance was good enough using rectangles that it was never needed.Giddens
thanks for pointing me to JSI. also you can search for quadtree or rtree and java. + I've done some work but I now know that I could have done better and had not yet the time to implement these tricks: karussell.wordpress.com/2012/05/29/…Prink

© 2022 - 2024 — McMap. All rights reserved.