Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql rails geocoder near_by result join查询返回活动记录关系_Sql_Ruby On Rails_Activerecord_Rails Geocoder - Fatal编程技术网

Sql rails geocoder near_by result join查询返回活动记录关系

Sql rails geocoder near_by result join查询返回活动记录关系,sql,ruby-on-rails,activerecord,rails-geocoder,Sql,Ruby On Rails,Activerecord,Rails Geocoder,产生的结果 地理编码器的位置=位置。近([参数[:纬度]、参数[:经度]、参数[:半径],:单位=>:公里) 及 locations\u by\u where=Location.where(:id=>[7,10,9,8]) 都一样 location_by_geocoder output is [#<Location id: 7, country: nil, state: nil, city: nil, locality: nil, name: "Coffee On Canvas", l

产生的结果 地理编码器的位置=位置。近([参数[:纬度]、参数[:经度]、参数[:半径],:单位=>:公里)

locations\u by\u where=Location.where(:id=>[7,10,9,8]) 都一样

location_by_geocoder output is

 [#<Location id: 7, country: nil, state: nil, city: nil, locality: nil, name: "Coffee On Canvas", latitude: "12.93516201597191", longitude: "77.63097871416265", created_at: "2014-03-29 15:20:34", updated_at: "2014-03-29 15:20:34", address: "#84, S.T.Bed Layout, 4th Block Koramangala", id_location: "cd49dfa966245b12">,
 #<Location id: 10, country: nil, state: nil, city: nil, locality: nil, name: nil, latitude: "12.93516201597191", longitude: "77.63097871416265", created_at: "2014-03-30 14:47:03", updated_at: "2014-03-30 15:20:52", address: nil, id_location: "60f7f024d37c74f9">,
 #<Location id: 9, country: nil, state: nil, city: nil, locality: nil, name: "Cafe Coffee Day", latitude: "12.93434671368444", longitude: "77.6256083701297", created_at: "2014-03-29 15:41:42", updated_at: "2014-03-29 15:41:42", address: "Mango Suites,", id_location: "8db810b6762fd784">,
 #<Location id: 8, country: nil, state: nil, city: nil, locality: nil, name: "Cafe Coffee Day", latitude: "12.932626125142486", longitude: "77.62338638305664", created_at: "2014-03-29 15:31:53", updated_at: "2014-03-29 15:31:53", address: "BPCL RAJAJINAGAR,Dr.RajkumarRoad, Rajajinagar", id_location: "ff71f5a0b4de9e1b">]

location_by_where output is
  [#<Location id: 7, country: nil, state: nil, city: nil, locality: nil, name: "Coffee On Canvas", latitude: "12.93516201597191", longitude: "77.63097871416265", created_at: "2014-03-29 15:20:34", updated_at: "2014-03-29 15:20:34", address: "#84, S.T.Bed Layout, 4th Block Koramangala", id_location: "cd49dfa966245b12">,
 #<Location id: 8, country: nil, state: nil, city: nil, locality: nil, name: "Cafe Coffee Day", latitude: "12.932626125142486", longitude: "77.62338638305664", created_at: "2014-03-29 15:31:53", updated_at: "2014-03-29 15:31:53", address: "BPCL RAJAJINAGAR,Dr.RajkumarRoad, Rajajinagar", id_location: "ff71f5a0b4de9e1b">,
 #<Location id: 9, country: nil, state: nil, city: nil, locality: nil, name: "Cafe Coffee Day", latitude: "12.93434671368444", longitude: "77.6256083701297", created_at: "2014-03-29 15:41:42", updated_at: "2014-03-29 15:41:42", address: "Mango Suites,", id_location: "8db810b6762fd784">,
 #<Location id: 10, country: nil, state: nil, city: nil, locality: nil, name: nil, latitude: "12.93516201597191", longitude: "77.63097871416265", created_at: "2014-03-30 14:47:03", updated_at: "2014-03-30 15:20:52", address: nil, id_location: "60f7f024d37c74f9">]
location\u by\u地理编码器输出为
[#,
#,
#,
#]
输出所在位置的位置
[#,
#,
#,
#]
但在联接中使用它时,两者都会产生不同的结果

   books = books.joins(:location).merge(locations_by_geocoder) 

   produces

[#<Book id: 10, created_at: "2014-03-30 14:47:03", updated_at: "2014-03-30 15:20:52">]



  query syntax is

 SELECT locations.*, 6371.0 * 2 * ASIN(SQRT(POWER(SIN((12.9398981 - locations.latitude) * PI() / 180 / 2), 2) + COS(12.9398981 * PI() / 180) * COS(locations.latitude * PI() / 180) * POWER(SIN((77.6275559 - locations.longitude) * PI() / 180 / 2), 2))) AS distance, CAST(DEGREES(ATAN2( RADIANS(locations.longitude - 77.6275559), RADIANS(locations.latitude - 12.9398981))) + 360 AS decimal) % 360 AS bearing FROM `books` INNER JOIN `locations` ON `locations`.`id` = `books`.`location_id` WHERE (locations.latitude BETWEEN 12.930904883940814 AND 12.948891316059187 AND locations.longitude BETWEEN 77.61832835502157 AND 77.63678344497843 AND 6371.0 * 2 * ASIN(SQRT(POWER(SIN((12.9398981 - locations.latitude) * PI() / 180 / 2), 2) + COS(12.9398981 * PI() / 180) * COS(locations.latitude * PI() / 180) * POWER(SIN((77.6275559 - locations.longitude) * PI() / 180 / 2), 2))) <= '1') ORDER BY distance ASC
    where as 

    books = books.joins(:location).merge(locations_by_where)

    produces

[#<Book id: 11, title: "ggn", author: "steven jobs,steve jobs", isbn_10: "1572846933", isbn_13: "1932841660", edition: "1", print: nil, publication_year: 2011, publication_month: "2011", condition: "", value: nil, status: nil, stage: nil, description: "", visits: 38, user_id: 5, prefered_place: nil, prefered_time: nil, created_at: "2014-01-01 08:13:00", updated_at: "2014-03-30 14:47:35", rating: nil, image: nil, publisher: nil, goodreads_id: nil, ext_image_url: nil, pages: nil, language_code: nil, barter_type: nil, location_id: 10, id_book: nil>]

and query syntax is 

SELECT `books`.* FROM `books` INNER JOIN `locations` ON `locations`.`id` = `books`.`location_id` WHERE `locations`.`id` IN (7, 10, 9, 8)
books=books.join(:location).merge(地点由地理编码者指定)
生产
[#]
查询语法是

选择位置。*,6371.0*2*ASIN(SQRT(功率(SIN((12.93981-位置.纬度)*PI()/180/2),2)+COS(12.93981*PI()/180)*COS(位置.纬度*PI()/180)*功率(SIN((77.6275559-位置.经度)*PI()/180/2))作为距离,投射(度数(ATAN2(弧度(位置.经度-77.6275559),弧度)(locations.latitude-12.9398981))+360作为小数点)%360作为轴承从“位置”上的“books”内部连接“locations”.“id”=“books”.“location_id”其中(locations.latitude介于12.930904883940814和12.948891316059187之间,locations.经度介于77.618328355502157和77.63678344497843之间,以及6371.0*2*ASIN(SQRT(功率(SIN((12.93981-locations.latitude)*PI()/180/2),2)+COS(12.93981*PI()/180)*COS(locations.latitude*PI()/180)*POWER(SIN((77.6275559-locations.longitude)*PI()/180/2))问题与locations.near中的近范围有关


您最终是如何解决的?我也遇到了类似的问题