2

ハーバシン式に関連する奇妙な問題が発生しています。私のアプリケーションでそれが行われる方法は次のとおりです。

select lat,long,distance from(
        select lat,long,( 6371 * acos( cos( radians("+testLatitude.to_s+") ) * cos( radians( lat ) ) * cos( radians( long ) - radians("+testLongitude.to_s+") ) + sin( radians("+testLatitude.to_s+") ) * sin( radians( lat ) ) ) ) as distance
        from available_people) as dt where distance < "+distance.to_s+" order by distance

available_peopleテーブルに personName があることは 100% 確信していますが、以下のクエリを実行できません。列が存在しないというエラーが表示されます。

select lat,long,distance from(
            select personName,lat,long,( 6371 * acos( cos( radians("+testLatitude.to_s+") ) * 

    cos( radians( lat ) ) * cos( radians( long ) - radians("+testLongitude.to_s+") ) + sin( radians("+testLatitude.to_s+") ) * sin( radians( lat ) ) ) ) as distance
                from available_people) as dt where distance < "+distance.to_s+" order by distance

考えられる理由は何ですか。personName 列と緯度経度情報を取得できますか?

4

1 に答える 1

0

Without seeing the exact error (you really should include it) I'd say you should prefix personName with the table i.e. available_people.personName or dt.personName (if I'm reading your query correctly).

Second, albeit unrelated, what column type are you using for your lat/lng columns? Is this using mysql? As floats?

If that's the case, then you will run into crippling performance issues once your table holds enough records. I've run into this problem with ~50k records, where queries were taking 2 minutes or more.

If you're working with geospatial data, consider using Postgres+PostGIS or MongoDB. These solutions have geospatial indexing to make your queries ultra fast and functions so that you won't have to do haversine or spherical law of cosines stuff yourself.

于 2012-12-11T07:48:47.380 に答える