samedi 6 avril 2019

Using Google's Geolocation with json to autocomplete longitude and latitude

I am trying to create autoset variables to a response from Google's API key. From the googling I've done it seems like this is how I should be autosetting the lng and lat, but I'm not sure how to parse the data received from the API with json. What should I do? Am I on the right track? I also decided to keep my API key out for the post, but I do have it when testing.

class Post < ApplicationRecord
    has_one_attached :avatar
    response = 'https://www.googleapis.com/geolocation/v1/geolocate?key={API}'
    response.to_json(only: [:lng][:lat])
    self.lng = response['lng']
    self.lat = response['lng']
end




Aucun commentaire:

Enregistrer un commentaire