More specifically, how to test further? I saw another post where the answer used a hexdump. How might I try this, and should I?
Here's my trying in console...
variables: myl is my latitude value from my database. ul is the value from an api. ll is where I hand retyped the value:
ruby-1.9.2-p180 :106 > myl=a.latitude #=> "42.3471841"
ruby-1.9.2-p180 :107 > ul=@events[30].xpath('venue')[0]['lat']
=> "42.3471836"
ruby-1.9.2-p180 :108 > myl==ul #=> false
ruby-1.9.2-p180 :109 > myl==ul.to_i #=> false
ruby-1.9.2-p180 :110 > myl.to_i==ul.to_i #=> true
ruby-1.9.2-p180 :111 > Venue.find_by_latitude(ul) #=> nil
ruby-1.9.2-p180 :112 > Venue.find_by_latitude(ul.to_i) #=> nil
ruby-1.9.2-p180 :113 > Venue.find_by_latitude(ul.to_s) #=> nil
ruby-1.9.2-p180 :114 > ul #=> "42.3471836"
ruby-1.9.2-p180 :115 > myl.class #=> String
ruby-1.9.2-p180 :116 > ul.class #=> String
ruby-1.9.2-p180 :117 > ll="42.3471836" #=> "42.3471836"
ruby-1.9.2-p180 :118 > myl==ll #=> false
ruby-1.9.2-p180 :119 > ul==ll #=> true
Any suggestions would be most helpful! The goal is to use latitude and longitude to identify a place already stored in my database, since names of a place are not always unique.
Two things:
As I understand it, you're envisioning these things as numbers, not strings, so it's probably best to convert them before you make the comparison.
Second, since the strings aren't really equal, but fairly close as latitudes go, I'm going to go out on a limb and guess that you're really trying to compare them with some allowed margin of error. Like so (assuming myLatitude
and apiLatitude
are numbers):
(myLatitude - apiLatitude).abs < 0.000001
And (while you're at it) make sure that your longitude convention (-180 to 180 vs. 0 to 360) is consistent when you're comparing those.