Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:16:03+00:00 2026-06-14T13:16:03+00:00

I have Thinking Sphinx indexing locations all over the US and I need to

  • 0

I have Thinking Sphinx indexing locations all over the US and I need to find locations closest to a certain lat/lon. In the simplest example, I use the lat/lon of a particular city (lat/lon pulled from Google Maps API) and do a search, sorting by the closest location first.

The problem is, when I search for locations in New York City, it gives me results in Austin, Texas. When I search for location in Austin, I get Jersey Shore, Penn. Each city search gives me results in a completely different city. I’m not even sure where to begin with a problem like this.

Here is my index definition. (The location has an associated city object that also has a lat/lon, hence the location.latitude)

Location:

Thinking Sphinx

define_index do
    indexes :name
    indexes :description
    indexes city.name, :as => :city_name

    has "RADIANS(locations.latitude)",  :as => :latitude,  :type => :float
    has "RADIANS(locations.longitude)", :as => :longitude, :type => :float

    set_property :latitude_attr => :latitude, :longitude_attr => :longitude

    # set_property :delta => true
end

###############################################################

Without setting the latitude_attr property, I kept getting the error:

Sphinx Daemon returned error: index location_core: unknown latitude attribute 'latitude'

Search command:
Location.search(:geo => [city.latitude, city.longitude], :order => "@geodist ASC, @relevance DESC", :per_page => 5)

Any help that can be provided to get me going in the right direction is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:16:05+00:00Added an answer on June 14, 2026 at 1:16 pm

    "RADIANS(locations.latitude)" converts from degrees, which you are probably using in your database, so you have to convert :geo => [city.latitude, city.longitude] to Radians too.
    i.e.

    :geo => Geocoder::Calculations.to_radians([city.latitude, city.longitude])
    

    So i think its “working” because both is now degrees OR your database fields were Radians anyway and the convertion was not needed. But docs are saying:

    Keep in mind, though, that Sphinx needs these values to be floats, and
    tracking positions by radians instead of degrees. If this isn’t the
    case in your own database (which isn’t a surprise – most people store
    the values as degrees), then you’ll need to manually convert columns
    for the attributes:

    http://pat.github.com/ts/en/geosearching.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Ruby on Rails 3.1 application and i use for Sphinx + Thinking
I have Thinking Sphinx setup and working however I am having a problem getting
I have successfully got Thinking Sphinx working with Geolocation on an associated model. Happy
I have Sphinx and Thinking Sphinx 2.0.5 installed on my application and when I
I have a thinking-sphinx app and oddly enough the files in /db/sphinx/development/ have not
I have a Technique model which belongs_to User and is indexed by Thinking Sphinx.
I have database of products and I use Thinking Sphinx to search through them.
I have a Ruby on Rails site that uses thinking sphinx for searching a
I am using Sphinx with the Thinking Sphinx plugin. I have indexed a model
I have a table Blog belongs to User through user_id. I'm using thinking sphinx

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.