[Rails] Google Maps API Description when latitude and longitude cannot be saved

Introduction

When I used the googlemap API in the postscript of the article I wrote earlier, I was addicted to the fact that the address was registered but the latitude and longitude were not saved, so I will leave it as a postscript.

[Rails] google maps api How to post and display including map information

What you want to achieve

I can enter the address and post it, and it is saved in the database, but I want to solve the problem that the latitude and longitude are not saved.

About geocoder

Looking at various articles, it seems that the accuracy of geocoder may not be very good unless nothing is set. In order to solve it, it seems that you should set it so that you can use the information source of Google Map API.

Create geocoder.rb file

Let's implement it now.

Create a geocoder.rb file in the config folder.

Terminal


$ bin/rails g geocoder:config

The above description will create the config / initializers / geocoder.rb file.

We will edit the created file.

geocoder.rb


Geocoder.configure(
  # Geocoding options
  # timeout: 3,                 # geocoding service timeout (secs)
   lookup: :google,         # name of geocoding service (symbol)
  # ip_lookup: :ipinfo_io,      # name of IP address geocoding service (symbol)
  # language: :en,              # ISO-639 language code
   use_https: true,           # use HTTPS for lookup requests? (if supported)
  # http_proxy: nil,            # HTTP proxy server (user:pass@host:port)
  # https_proxy: nil,           # HTTPS proxy server (user:pass@host:port)

#YOUR_API_Enter your API key in KEY.
   api_key: YOUR_API_KEY,               # API key for geocoding service
  # cache: nil,                 # cache object (must respond to #[], #[]=, and #del)
  # cache_prefix: 'geocoder:',  # prefix (string) to use for all cache keys

  # Exceptions that should not be rescued by default
  # (if you want to implement custom error handling);
  # supports SocketError and Timeout::Error
  # always_raise: [],

  # Calculation options
  # units: :mi,                 # :km for kilometers or :mi for miles
  # distances: :linear          # :spherical or :linear
)

With this, it seems that it will be possible to improve the accuracy of geocoder and investigate more detailed locations.

At the end

That's all for solving my problem! There may be other possible causes such as description mistakes and missing processing, but I hope you find it helpful!

Recommended Posts

[Rails] Google Maps API Description when latitude and longitude cannot be saved
[Google Maps API] Map is not displayed and becomes blank [Rails]
matplotlib image cannot be renamed and saved
[Rails] google maps api How to post and display including map information
[Rails] Displaying Google Maps using Google Maps API and searching routes between multiple points
[Rails] How to calculate latitude and longitude with high accuracy using Geocoding API and display it on Google Map
Book registration easily with Google Books API and Rails
YOLP: Extract latitude and longitude with Yahoo! Geocoder API.
Beginners of Google Maps API and Twitter API made "tweet map"
When USB cannot be formatted
When pydub cannot be installed
[Ruby on Rails] Display and pinning of GoolgeMAP using Google API