cloudsearch / cloudsearchdemos

Demos for using Amazon Cloudsearch
13 stars 8 forks source link

Represeting locations in Amazon CS #2

Open OddOneOut opened 10 years ago

OddOneOut commented 10 years ago

Hello again,

Right now we're following this article to save locations in Amazon CS:

http://docs.aws.amazon.com/cloudsearch/latest/developerguide/geosearch.locations.html

But instead I see that you guys only save these values in the demo:

What is the recommended way?

Also, taken from the demo:

function getBoundaryQuery(){
    var lon = boundary.lon;
    var lat = boundary.lat;
    var deg = _degCols;
    var bq = null;
    if ( lon.min <= lon.max ) {
        bq = "(and "+ deg.lat +":" + lat.min + ".." + lat.max + " "+ deg.lon +":" + lon.min + ".." + lon.max + ")";
    } else {
        var bq1 = "(and "+ deg.lat +":" + ".." + lat.max + " "+ deg.lon +":" + ".." + lon.max + ")";
        var bq2 = "(and "+ deg.lat +":" + lat.min + ".." + " "+ deg.lon +":" + lon.min + "..)";
        bq = "(or " + bq1 + " " + bq2 + ")";
    }
    return bq;
}

I'm not quite sure if these checks are enough? Since I believe things should be handled differently when lat.min > lat.max.

Please advise, thanks.

TomCloud commented 10 years ago

You are probably correct. I believe that case should only occur when wrapping around the north or south poles.

patches welcomed. :-)

naberly commented 10 years ago

@TomCloud Do you recommend we simply use...: Latitude: (real latitude + 90) * 100 Longitude: (real longitude + 180) * 100 ...for storing values in CloudSearch instead of the formula described in http://docs.aws.amazon.com/cloudsearch/latest/developerguide/geosearch.locations.html

TomCloud commented 10 years ago

There are many ways to represent locations and distance on the globe.

For most of what I do, like finding the nearest pizza parlor, a simple approximation works, and I treat the globe as flat and latitude,longitude as X,Y coordinates. Since for most "find a restaurant" applications, the straight-line distance is an approximation of the best route on streets to the restaurant, this representation isn't an issue, and is simple and direct. The example in the documentation is accounting for the curvature of the earth. More complex, slower, but slightly more accurate. And there are many other possible approaches.

There's more discussion here: http://www.slideshare.net/mikebohlig/geospatial-search-with-amazon-cloudsearch

I believe with the Haversine function, you have to represent the degrees in radians, so you'd have to use a different encoding.

I usually just start with the simplest approach, and only add complexity as needed.

Tom

From: spotonconnect notifications@github.com<mailto:notifications@github.com> Reply-To: cloudsearch/cloudsearchdemos reply@reply.github.com<mailto:reply@reply.github.com> Date: Monday, November 18, 2013 12:30 PM To: cloudsearch/cloudsearchdemos cloudsearchdemos@noreply.github.com<mailto:cloudsearchdemos@noreply.github.com> Cc: "Hill, Thomas" tomhill@a9.com<mailto:tomhill@a9.com> Subject: Re: [cloudsearchdemos] Represeting locations in Amazon CS (#2)

@TomCloudhttps://github.com/TomCloud Do you recommend we simply use...: Latitude: (real latitude + 90) * 100 Longitude: (real longitude + 180) * 100 ...for storing values in CloudSearch instead of the formula described in http://docs.aws.amazon.com/cloudsearch/latest/developerguide/geosearch.locations.html

— Reply to this email directly or view it on GitHubhttps://github.com/cloudsearch/cloudsearchdemos/issues/2#issuecomment-28734930.