SimpleDB does not currently offer any built-in spatial search operations, but this does not mean that this is not possible. There are several ways to implement geospatial searches in non-geospatial information databases, such as SimpleDB, and they all focus on the idea of using a database to get a rough first choice based on a geospatial bounding box and then filtering the returned data in your application using more exact algorithms such as the Haversin Formula .
You can save the numerical attributes of latitude and longitude as (zero and normalized), and then run a double range query ( lat >= minLat and lat <= maxLat and lon >= minLat and lon <= maxLat ), but since none of these predicates is not selective (each predicate corresponds to many elements), it is not perfect (see Configuring queries ).
It is best to use GeoHashes .
Geohash offers features such as arbitrary precision, similar prefixes for nearby positions, and the ability to gradually remove characters from the end of the code to reduce its size (and gradually lose accuracy).
As a practical example, Geohash 6gkzwgjzn820 decodes the coordinates -25.382708 and -49.265506, while Geohash 6gkzwgjz decodes to -25.383 and -49.266, and if we take a similar position in the same region, for example, -25.427 and -49.315, we can see that it is encoded as 6gkzmg1w (note the similar prefix).
From http://geohash.org/site/tips.html
With position positions as GeoHashes, you can use the like operator to find the bounding box ( where GeoHash like '6gkzmg1w%' ), but since the like operator is expensive ( Comparison Operators ), it would be better to denormalize the data by saving each level of the GeoHash prefix (how much depends on your desired search accuracy) as a separate attribute (GeoHash6 GeoHash8, etc.), and then use a simple predicate equality ( where Geohash8 = '6gkzmg1w' ).
Now on the back of GeoHash. Since you cannot make any assumptions that GeoHash is concentrated in your search box, you also need to search for all neighboring prefixes. This process is superbly described by geohash-js
Geohash also has the property that as the number of digits decreases (on the right), accuracy decreases. This property can be used for searching in the bounding box, since points located next to each other will be similar to Geohash prefixes.
However, since a given point may appear on the edge of a given Geohash, it is necessary to create a list of Geohash values in order to perform a real proximity search by point. Since the Geohash algorithm uses the base-32 numbering system, it is possible to obtain Geohash values surrounding any other data. Geohash values using a simple lookup table.
So, for example, 1600 Pennsylvania Avenue, Washington, DC decides: 38.897, -77.036
Using the geohash algorithm, this latitude and longitude are converted to: dqcjqcp84c6e
A simple bounding box around this point can be described by truncating this geohash: dqcjqc
However, 'dqcjqcp84c6e' is not centered inside 'dqcjqc', and searching inside 'dqcjqc' may miss some desired goals.
So instead, we can use the mathematical properties of Geohash to quickly calculate the neighbors "dqcjqc"; we find that they are: 'Dqcjqf', 'dqcjqb', 'dqcjr1', 'dqcjq9', 'dqcjqd', 'dqcjr4', 'dqcjr0', 'dqcjq8'
This gives us a bounding box around "dqcjqcp84c6e" of about 2 km x 1.5 km and allows you to search the database with just 9 keys: SELECT * FROM table WHERE LEFT (geohash, 6) IN ('dqcjqc', 'Dqcjqf', 'dqcjqb ',' dqcjr1 ',' dqcjq9 ',' dqcjqd ',' dqcjr4 ',' dqcjr0 ',' dqcjq8 ');
Translated to SimpleDB query, which will be where GeoHash6 in('dqcjqc', 'dqcjqf', 'dqcjqb', 'dqcjr1', 'dqcjq9', 'dqcjqd', 'dqcjr4', 'dqcjr0', 'dqcjq8') You will filter Haversine according to the results to get only those objects that are in the search radius.