qualtrics-map
A react-based component that displays an embedded Google Maps in Qualtrics.
Features
- Collection of multiple answers in one question.
- e.g., "From:" and "To:"
- Use either of address bar with autocomplete or map marker.
Installation
Google Maps API
This library uses Google Geocoding API, Maps Javascript API, and Places API.
Make sure you have a key to access those APIs.
Option 1 (use CDN)
Click to open
Copy https://cdn.jsdelivr.net/gh/keita-makino/qualtrics-map/dist/bundle.js <- this address (not the contents of this address) and proceed to "Header settings".
Option 2 (manual upload)
Click to open
Get bundle.txt
There are two ways to obtain your bundle.txt
. Choose one way as your needs and then proceed to "Qualtrics Survey Settings".
Using template
Download the template from the relaese page.
Build by yourself
Alternatively, you can build the component in your environment.
This approach is neeeded if you want to custom the component (placeholder text, button color, and others).
- Clone or download the repository.
npm ci
npm run build
Qualtrics Survey Settings
File Upload
- Go to the files library in Qualtrics.
- Upload the text file.
- Click the gear icon at the right of the uploaded file and select "Rename File".
- Select the uploaded file and click "View" button.
- Copy the URL of the file opened in the new window and proceed to "Header settings".
Header settings
- In the survey edit screen, click "Look & Feel" on right-top.
- Select "General" tab and then edit the "Header".
- Click the "<>" icon to enter coding-view.
- Copy and paste the following code, replacing the
[apiKey]
and[fileUrl]
with respectively the API key and the URL that you copied above.
<script>
var apiKeyGoogleMap = '[apiKey]';
var countryCode = '${loc://CountryCode}';
var postalCode = '${loc://PostalCode}';
</script><br />
<script src="[fileUrl]"></script>
Use it
- The question that you want add the map has to be set as "Text Entry" + "Form" question.
- Add / remove text fields and set the field tag as you need. (e.g., Two text fields named "From:" and "To:").
- In the question, click the gear icon and then "Add Javascript..."
- Use the following code.
- If you need to set a default center location, use the latter one.
- All done!
Qualtrics.SurveyEngine.addOnload(function () {
document
.getElementById(this.questionId)
.querySelectorAll('[role*=presentation]')[0].style.display = 'none';
});
Qualtrics.SurveyEngine.addOnReady(function () {
mapRender(apiKeyGoogleMap, document.getElementById(this.questionId));
});
// If you need to set a default center
Qualtrics.SurveyEngine.addOnReady(function () {
mapRender(apiKeyGoogleMap, document.getElementById(this.questionId), {
location: {
lat: 50,
lng: -100,
},
zoom: 12, // Optional
});
});