You have an adress like “1600 Amphitheatre Parkway, Mountain View, CA”.
You need latitude and longitude of that adress.
General idea for the Solution:
Ask the Google-API: https://maps.googleapis.com/maps/api/geocode/json?address=YOUR_ADRESS&key=YOUR_GOOGLE_KEY
- YOUR_ADRESS: whatever you server, but url encoded
- YOUR_GOOGLE_KEY: Get one via https://developers.google.com/maps/documentation/javascript/get-api-key
Solution in detail:
Guess you have JSON-data and each item has an adress. For each adress we’d like to know latitude and longitude. For that we first create a new JCI-Template with this settings: Template-Text:
{{ _context | json_encode }}Name of template: googleconvadr2latlon
URL (##param1## we explain later):
https://maps.googleapis.com/maps/api/geocode/json?address=##param1##&key=YOUR_GOOGLE_KEYCachetime in secondes (this is how long a GoogleAPI-request is locally stored, to avoid many requests on the API): e. g. 31536000 seconds for 1 year
To use this JCI-“googleconvadr2latlon”-Template together with JSON-data you need another JCI-Template.
Template-Text (param1 is used in the other template at “##param1##”):
{% set adr = "1600 Amphitheatre Parkway, Mountain View, CA" %} {% set adr_encoded = adr | url_encode %} {% set sc = '[jsoncontentimporterpro orderofshortcodeeval=10 nameoftemplate="googleconvadr2latlon" param1="'~adr_encoded~'"]' %} {% set scexe = (sc | doshortcode | json_decode(TRUE)) %} {% set lat = scexe.results.0.geometry.location.lat %} {% set lng= scexe.results.0.geometry.location.lng %} {{adr}} is at {{lat}},{{lng}}Name of template: doadr2latlon
URL: either your JSON-URL or “dummyrequest” for testing
In action:
1600 Amphitheatre Parkway, Mountain View, CA is at ,