geokit

Using Rails 3 with Geokit-rails3 location gem

╄→尐↘猪︶ㄣ 提交于 2020-01-13 13:05:41
问题 I am trying to use the geokit-rails3 gem for geolocation information in a rails application. I have a simple model: class Location < ActiveRecord::Base def lookup_ip_information(post_ip) ip = post_ip location = IpGeocoder.geocode(ip) puts location.full_address lat = location.lat lng = location.lng end end When I call this method with request.remote_ip from my controller, it's throwing an error: uninitialized constant Location::IpGeocoder 回答1: I just had this issue and resolved it by entering

Rails Geokit Too Many Queries Error

柔情痞子 提交于 2020-01-06 06:53:55
问题 I was trying to do a little app to test the gem "geokit", "~> 1.8.4" It was working at the beginning but then started raising this error Geokit::Geocoders::TooManyQueriesError at most I did 100 queries with this line of code suggested_bounds = Geokit::Geocoders::GoogleGeocoder.geocode(params[:location]) Can anyone help me Thank you 回答1: Google has a limit of 2,500 requests per 24 hour period. I think they also restrict it if you do too many in a short like (like many within a second). Are you

Rails 3.1.0, geokit, with error acts_as_mappable

邮差的信 提交于 2019-12-31 04:43:05
问题 I am getting the undefined local variable or method `acts_as_mappable' error when using geokit, and after tons of Goggling and attempts, I cannot seem to be able correct the problem. Basically, I have the following gems installed: geokit (1.6.0, 1.5.0) geokit-rails31 (0.1.3) and have the following in my model class House < ActiveRecord::Base acts_as_mappable end and Gemfile: gem 'geokit', '>= 1.5.0' gem 'geokit-rails31' I get the error with or without doing the following in my local app.

Rails: Geokit incorrectly converting IPv4 address to latitude and longitude

这一生的挚爱 提交于 2019-12-25 05:25:36
问题 I want to convert two IPv4 addresses to latitude and longitude, then calculate the geographical distance between them. Geokit says it can do this. Seattle: a = Geokit::Geocoders::GoogleGeocoder.geocode("207.244.147.34") a.lat => 37.0483944, a.lng => 37.3421261 (should be 47.5839, -122.2995) Edit: Okay below is an IP address for UK not SF, but its still UK not Turkey. San Francisco: b = Geokit::Geocoders::GoogleGeocoder.geocode("5.68.123.155") a.lat => 14.6478672, a.lng => 120.9880659 (should

Rails: Converting from MySQL to PostGres breaks Geokit Distance Calculations?

人走茶凉 提交于 2019-12-24 00:07:18
问题 I recently switched my database from MySQL to PostGres. I also use GeoKit. When I started my app up with the new database already seeded, I get the following error: PGError: ERROR: function radians(character varying) does not exist LINE 1: ...COS(0.661045389762993)*COS(-2.12957994527573)*COS(RADIANS(ti... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. Anyone know why this is breaking now? I know GeoKit still works because it's still

Why does Postgresql fail with Geokit like this?

£可爱£侵袭症+ 提交于 2019-12-23 02:38:46
问题 I've just started playing with geokit with Rails for an app I am building. I have got my recorda getting geocoded, but then when I go into the console to have a look at what I can do it with and it blew up with the following: user is a user object with lat and lng from my database >> Restaurant.find(:all, :origin => user) Restaurant Load (0.0ms) PGError: ERROR: operator does not exist: numeric - character varying LINE 1: ...*, SQRT(POW(111.1819*(-33.872517-restauran... ^ HINT: No operator

Change value of request.remote_ip in Ruby on Rails

强颜欢笑 提交于 2019-12-18 15:13:32
问题 For test purposes I want to change the return value of request.remote_ip. While being on my development machine it returns always 127.0.0.1 as it should but I would like to give myself different fake IPs to test the correct behavior of my app without deploying it to an live server first! Thank you. 回答1: If you want this functionality in your whole application, it might be better/easier to override the remote_ip method in your app/helpers/application_helper.rb : class ActionDispatch::Request

Combine arrays of conditions in Rails

社会主义新天地 提交于 2019-12-18 03:47:29
问题 I'm using the Rails3 beta, will_paginate gem, and the geokit gem & plugin. As the geokit-rails plugin, doesn't seem to support Rails3 scopes (including the :origin symbol is the issue), I need to use the .find syntax. In lieu of scopes, I need to combine two sets of criteria in array format: I have a default condition: conditions = ["invoices.cancelled = ? AND invoices.paid = ?", false, false] I may need to add one of the following conditions to the default condition, depending on a UI

Add distance to a particular latitude/longitude position

荒凉一梦 提交于 2019-12-12 09:22:08
问题 Rails 4 + Postgres. New to geospatial. Happy to accept solutions that involve RGeo, Geokit, Geocoder, or any other gem that helps solve this issue. Model contains two fields latitude and longitude . I have an offset attribute that contains a distance in meters and an orientation attribute that contains one of the 4 cardinal directions (N, E, W, S). Example: offset: 525.5 orientation: W What's a standard way of adding the offset distance to the lat-long position, to give me a new lat-long pair

Which post code is the nearest with Geokit?

痞子三分冷 提交于 2019-12-11 12:14:00
问题 I'm using geokit to give me distances between two post codes. I need to determine which post code is the nearest. point_a = Geokit::Geocoders::GoogleGeocoder.geocode "se18 7hp" alpha = ["cr0 3rl", "W2 1AA"] miles = alpha.map do |m| point_a.distance_to(m) end miles.min # => 11.005310790913377 How do I do the reverse of miles.min to get to know which post code was the nearest from point_a? 回答1: To get the index of an array element, use Array#index So, in your case, it will be alpha[miles.index