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
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.
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.
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.
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