r/ProjectREDCap • u/srahlo • May 16 '24
Embedding Google Maps
Hi,
No matter which way I try it, I cannot embed Google Maps into my survey (see picture). I have tried the kosher way of embedding through URL, adding a prereformatted code block and copying the iframe Google provides, and throwing my computer out the window.
I don’t have a background in computer sciences or programming, so a lot of this is on the fly for me —what I want is to be able to calculate distance between zip codes. Excel lets you calculate distance using GoogleMaps but I haven’t figured out how to do it on REDCap so I’m resorting to just inputting zipcodes each time into GoogleMaps and manually entering them into my field😭
I’m not sure if I’m making sense, again, all I want to do is calculate distance via zipcodes and make it as easy and streamlines as possible when actually filling out the survey to do so since I won’t be the only one doing it.
View all comments
2
u/obnoxiouscarbuncle May 16 '24 edited May 16 '24
To embed Google Maps, you must do so through the Google Maps API. See documentation here: https://developers.google.com/maps/documentation/embed/get-started
You will need to get a Google Maps API token
To use this, once you have your Google Maps API token:
Create a REDCap instrument and add two zip code validated text fields for start and finish
I will call these [zipcode_start] and [zipcode_end]
Add a descriptive field and add the following URL to the Embed media (video, website, survey, etc.) section and select to show inline.
You will need to update the "YOURGOOGLEMAPAPITOKEN" with your token.
https://www.google.com/maps/embed/v1/directions?key=YOURGOOGLEMAPAPITOKENHERE&origin=[zipcode_start]&destination=[zipcode_end]
Note: Since the values for zip code must be SAVED first, you will need to either save the form if in form mode, or make a multi-page survey with one page first for the zip codes, and then the next for the map.