It is not often, but you may find yourself in a position where the only sensible thing to do is use a clickable Google map.
Not because it is fun to do it, not because it looks cool, no: because it is user-friendly when you are asking for a location. (But it does look cool.)
Whatever you may think of Google in general and maps in particular: it is used on a huge scale, which means that you can find plenty of examples and that the api will most likely be supported for the duration of your study. Let's see how we can get a CRF like the one listed below. It has just one item and the map. When you click the map, the coordinates are copied to the CRF-item. When you save the CRF and open it again, a marker is placed.
If that's all you're looking for and you can't wait to start using it: here's the CRF.
fig. 1: what we want
The script is of course a bit different from our usual scripts, but it's quite understandable.
(Below is the script as used in the downloadable CRF, but with comments. We are pushing the OpenClinica-limits somewhat by using almost 2000 characters in the right_item_text. So if you want to copy and paste the script from this page, remove all comments and all spaces!)
In order to be able to use a map, we must include the api from google
Note the https: you can not include an http-file in an otherwise https-page.
The place, or div, for the map is defined at the top. Then we include jquery and we define what variables we will use, like var fldCoord, var map, etc. Next we define two functions: initMap() and createMarker().
Now everything is in place, so we draw the map by calling initMap();. And we create a marker, if the CRF-item has coordinates.
createMarker(coord, "name", "Saved location");
In this example we treated the coordinates as one item: but of course they are two variables of type long. The conversion from string to two longs is done by first taking the actual value in the CRF-item, for example (52.34147481539552, 4.904078543186188) and storing it in a variable called sc . Then we chop of the first and last character with sc = sc.substring(1, sc.length -1); so that makes 52.34147481539552, 4.904078543186188. Then we transform this string into an array, by splitting it at the comma: d_array = sc.split(",");. And now we can use the first and the second element of this array as the latitude and longitude of a location.
this page was last reviewed January 2016