Metadata Mapping: Under the Hood
We’ve had a lot of positive responses to the metadata mapping example referred to in a FileMaker 13 post last December. In this example, you can drag a photo onto a designated space and the location that the photo was taken will load in a map right there on the layout. If you’re interested in looking under the hood and learning how it’s done, this post is for you. Be sure to Download the example file to see this in action and pick it apart. Finally, this post assumes some FileMaker development proficiency in creating fields, scripts, and layouts.
The Metadata Mapping file contains three images in container fields, one global container “well” for dropping an image into, a global text field used for script triggering, and a web viewer displaying Google Maps. Dragging any one of the three photos into the well will cause the photo’s location to load in the web viewer below. This is possible because FileMaker 13 has the ability to read the metadata from the image (sometimes called EXIF tags). All digital cameras include some metadata with the photos they take. Typical tags include the camera make and model, image dimensions, and the date and time the photo was taken. The cameras on most smart phones are capable of including the latitude and longitude of the photo’s location; this is commonly referred to as geotagging. By combining FileMaker 13’s ability to read geotags with script triggers and a web viewer, drag-and-drop mapping becomes possible.
Dragging a geotagged image into the global container fires an OnObjectModify script trigger. The triggered script sets a global variable $$url then moves to the global text field using a Go to Field script step.
That Set Variable step is where the magic happens. Using the GetContainerAttribute() function, it derives the longitude and latitude of the image, then uses them to build a Google Maps URL. The full calculation is below.
Let ( [
// extract the latitude and strip out any hyphens if present
vLat = Substitute ( GetContainerAttribute ( MetaMap::g_Image ; "latitude" ); "-"; "" );
// extract the longitude and strip out any hyphens if present
vLon = Substitute ( GetContainerAttribute ( MetaMap::g_Image ; “longitude” ); “-“; “” );
// get the file name of the image to use as the label in the map.
vName = Substitute ( GetContainerAttribute ( MetaMap::g_Image ; “filename” ); “.jpg”; “” ) ];
// here’s where the URL is calculated
// output=embed supresses the huge sidebar on the left
vLat & “N ” & vLon & “W+(” & vName & “)&output=embed&hl=en” )
Oh yeah, sorry to be provincial about this, but my URL calculation supports locations in the north west quadrant of the globe. If you’re outside that chunk of the earth, you can tweak the calculation to suit.
OK, we’ve set the $$url variable that the web viewer uses to load the correct location, now we have to coerce the map into refreshing. That’s what the Go to Field script step is about. This step goes to the empty global text field which is configured with an OnObjectEnter script trigger. It’s script reloads the web viewer, refreshes the web viewer and commits the record. Just like that, you’ve got drag and drop mapping for your geotagged images.
For the sake of simplicity, I’ve glossed over a few of the nitty gritty details, so please be sure to grab a copy of the file you can pick apart for yourself. Hope you enjoy this fun example of just one of FileMaker 13’s new capabilities.