[1]
def get_coords(address)
coords = Geocoder.search(address)
self.lat = coords[0].data["lat"].to_f
self.lng = coords[0].data["lon"].to_f
end
On the front-end a user enters an address for a new TravelCenter, Restaurant, Lodging, or CoffeeShop. In Rails, I use Geocoder to get the latitude and longitude which are saved in the database. Then back on the front-end, I display a marker for each "place" in the given area.
The problem is, the coordinates are way way way way off when creating a new entry in this manner. The first image shows the latest TravelCenter in the Rails Console, and on the left side of the image shows the real world coordinates of the actual truck stop that it represents. Notice that the longitude is too far to the left. On the front end the blue dot that should be on the EAST side of the word Amarillo is on the WEST side instead.
So basically...what gives? Is there something wrong with this particular API?
Furthermore, is there a less messy way to get them coordinates? I have no idea why Geocoder.search returns an array and why the lat and lng are buried so deep.
Update: Left, expected location. Right, Actual location. Conclusion: Ruby Geocoder is garbage.