Update: Capturing Map Coordinates Into FileMaker

Dropping A Marker When The Map Loads

Update: Capturing Map Coordinates Into FileMaker

Following up from our previous post, a reader asked if it was possible to have the marker show automatically when the map loads, if there were coordinates previously selected. Depending how Google Maps is being used in a solution, this is a perfectly reasonable expectation of functionality. So, we decided to add this to the file and post an update. There was, however, one annoying little issue...

The Issue...

Dropping a marker when the map loads is generally not difficult if you know a little JavaScript and can understand the great documentation Google provides for this API. But in doing so, with the way we had things set up, every time we clicked on the map to select coordinates, we encountered the map reloading and centering on the place just clicked. This was not a good user experience.

So, we opted to handle this in a FileMaker way, which resulted in some changes/additions to the schema, scripting and web viewer.

How To Use The Demo

We've implemented a second layout, which we default to when opening the file. The original layout is accessible either via the usual layout menus or by clicking the blue button on the right above the map.

You can click around the map and the latitude and longitude fields will populate as before.

Once the marker is in the correct location, click the blue button to 'Use The Captured Coordinates'. This sets a couple new fields with the values selected.

Now, if you close the file and reopen it (or go into layout mode and back to browse mode), this forces the map to reload. The marker will drop at the selected coordinates and the map will be centered on the marker.

So, What's Changed?

Here's a quick rundown on what's different from the last demo:

  • We added a couple hidden divs at the end of the code that hold our latitude and longitude values.
  • The web viewer needs adjusting to do a similar substitution as we did previously with the Start Address field.
  • At the beginning of our Initialize function we grab the coordinates into variables for use in our code.
  • If coordinates exist in these variables, then when we load the map we use these. If not then we use the Start Address as before.
  • There are two new visible fields - SelectedLatitude and SelectedLongitude. These store the desired coordinates once they have been found on the map and the button is clicked.
  • There are two non visible fields - MapLoadLatitude and MapLoadLongitude. When the record is loaded, a script trigger runs that populates these fields with the values in the Selected fields. This is critical - if the fields being sent to the HTML are the same as the ones being used when the map is clicked, or the Selected fields, the map will refresh and center on that location.

There may be other ways to tackle this issue but we wanted to keep it simple and in the FileMaker world that many readers will be more familiar with than JavaScript. Also, the Selected fields may be one step too many, depending on how you intend to deploy this in your solution. It would be possible to just use the Lat/Lng fields in conjunction with the script trigger and MapLoad fields, but we wanted to bolt on to the previous demo and show options. Similarly, the HTML/JavaScript code could probably be streamlined but again we wanted to keep the original code as intact as possible so the differences can be explored.

The Demo File

You can download the revised demo file here.

Don't forget that you'll need to place the HTML in a global field or as a layout text object, and of course adjust all references to suit your solution.

Do go check out the Google Maps API documentation - click the Google Maps icon in the demo file to go directly to their site. There's so many possibilities and options that can add much value and functionality to your FileMaker solution.

  • Tags: FileMaker

Categories: The FMP Files

Comments (3)

  • Aki Armann Jonsson

    14 December 2016 at 03:53 |
    Thanks amillion!!
    This solution is brilliant and so valuable in our work. If you are ever in Iceland we will buy you a drink :)


  • Geert Schaerlaeken

    07 March 2017 at 14:44 |
    I've been looking for quite a while for a solution like this and absolutely love it. But apparantly it doesn't work in filemaker go 15 anymore because a web viewer can only reference a file located in the temporary folder in FMGO 15. Do you know if it is possible to get it to work in FMGO 15? Any help would be appreciated.


    • Duncan Baker

      07 March 2017 at 21:05 |
      Hi Geert. I just tested the demo file in FM Go 15.0.3 released in January and it appears to be working as expected. If you have any trouble with the demo file, let us know. If it's your own implementation, try checking all the code carefully. Good luck with it.


Leave a comment

You are commenting as guest. Optional login below.

Client Testimonials

  • Sounds Essential is a trusted partner on several demanding and highly complex development projects. Their technical skills, creativity, and most importantly, their grasp of our business needs has helped our company deliver sophisticated solutions to our (very happy) clients. Even when projects reach the "intense" stage, we really enjoy working with Sounds Essential.

    Pam Henry, Managing Partner
    Digital Spark LLC
  • Sounds Essential worked with our staff last year to create the first digital plant database in our organization’s history. This milestone not only benefits the day to day work flow of our organization, it creates the opportunity for us to share our data with others worldwide. Due to our niche high elevation ecosystems, we can share valuable insight about native plant communities and how they are adapting to climate change. Without the help from SE and funding from Stanley Smith Horticultural Trust this project would still be in conception. Working with SE made the development and implementation a pleasure for us gardeners.

    Kelly Holdbrooks, Exec. Director
    Southern Highlands Reserve
  • Sounds Essential is the best! Our company website and database are essential parts of our business. The website and database give us the professional look of who we are while also making our work flow so much easier! We highly recommend Sounds Essential.

    Charles Dwan, Owner
    Chefs Trading
  • Sounds Essential's team is the perfect combination of creativity, aesthetic vision, and technical expertise which enables them to provide innovative products. They are always responsive with questions, issues, and technical support and as the technology changes they adapt accordingly. We highly recommend Sounds Essential and they are indeed ‘essential’ to our business model.

    Wesley Wofford, Owner
    Wofford Sculpture Studio
  • Sounds Essential was a pleasure to work with from start to finish. With their guidance, we were able to update our website quickly and present a more polished and modern interface for our church. The documentation provided was clear and easy to follow, and they have been quick to respond to any questions.

    Kirsten Huscusson, Parish Administrator
    Church of the Incarnation
  • Between their exceptional level of service and versatility of skill, Sounds Essential is my first stop for anything from IT to creative... and they're my favorite partner, hands down.

    Leah G. Fallon, Owner
    Eleven Eleven Creative

Get the Latest

We occasionally send out news of general interest in our fields of specialty. If you'd like to stay up to date, please sign up according to your interests below.
Please wait