7 Replies Latest reply on Oct 12, 2010 1:51 PM by philmodjunk

    How do I compile a URL that includes several latitude

    morgannews

      Title

      How do I compile a URL that includes several latitude & longitude pairs?

      Post

      I have Filemaker Pro 7 and a database with 144 records of trees. Each record has a different set of latitude and longitude numbers in decimal form, corresponding to the location of each tree.

      I'm trying to construct the URL for a Google Map that places push pins at the lat/longs of a group of records found in the database.

      I know how to do this with one record, with all the front-end portion of the necessary URL and one record's lat/long info. But I want to plot up to 10 pins on the same Google map at the same time.

      I know the concept of what I need for the URL in order to do this. The output format I need would be produced by something like this, using my variables collected from my group of found records, with each group of lat/longs separated by the pipe character:

      latitude & "," & longitude & "|" & latitude & "," & longitude & "|" &...

      When generated, the portion of the URL I need has to look like this:

      49.2677,-123.1338|49.2675,-123.1292|... up to 10 lat/longs.

      The problem is that I don't have enough experience with Filemaker to figure out how to get from the need to the output. ( I don't even know how to form the question in a way that I could do a Google search for possible examples done by others.) Is it a calculation? Is it a script? A combination of the two? I've spent a while trying to work it out, but to no avail.

      How do I tell Filemaker to gather all the lat/long data in my found set and produce that output text string for the set, so I can add it to the back end of the URL?

      Thanks.

      /Peter Morgan 

        • 1. Re: How do I compile a URL that includes several latitude & longitude pairs?
          philmodjunk

          Each latitude and longitude pair is in a different record? Are these records listed in a portal by any chance?

          I skipped from 5.5 to 10, so don't know off hand if you have these capabilities or not:

          Does FileMaker 7 have the List function?

          Does FileMaker 7 support variables? (look for a script step called set variable.)

          • 2. Re: How do I compile a URL that includes several latitude & longitude pairs?
            morgannews

            I'm not sure with this forum how to handle quotes from another answer, but let's do it this way:

            Phil, you asked:

            1. Each latitude and longitude pair is in a different record?
            Yes. Each record contains a text field for latitude, another for longitude, and I also have a calculation field that concatenates those two with the comma between them. It would be straightforward for me to add the pipe character if need be.
            1.  Are these records listed in a portal by any chance?
            No. FM 7 handles portals, but I've never used one. After your comment I read up on portals in FM's Help file, along with some related variables. It seemed potentially useful, but when I create a portal, it won't refer to the existing database in the initial set-up dialog, and you can't set other aspects in the dialog until you solve that problem.
            1. I skipped from 5.5 to 10, so don't know off hand if you have these capabilities or not:
            1.  
              1. Does FileMaker 7 have the List function?

            No. It has several functions that deal only with value lists.

            1.  
              1. Does FileMaker 7 support variables? (look for a script step called set variable.)

            It does not have that script step. It has the 'Let' function though, which might help in handling variables -- 

            Let ( {[} var1 = expression1 {; var2 = expression2...]} ; calculation ).

            • 3. Re: How do I compile a URL that includes several latitude & longitude pairs?
              philmodjunk

              With regards to portals, you first need to define a relationship (and a relationship can link a table to itself if needed). A portal plus the list function would have made this simpler, but you don't have either at this point, so that requires a more complicated solution. I have one more question, however: You have 144 records, but only plan to use up to 10 lat, long pairs in the web page. How will the script know which group of records to refer to in order to build your URL expression? The first 10 records of the found set or is there some common value  such as a general geographic region involved here?

              Assuming you can pull the records up in a found set, you can loop through the records building a list of latitude and longitude pairs in a global text field. After the loop ends, you have what you need to set up a calculated expression to use as your URL.

              Set Field [YourTable::gLatLong ; "" ]
              Go To Record [ First ]
              Loop
                Set FIeld [YourTable::gLatLong ; YourTable::gLatLong & YourTable::latitude & "," & YourTable::longitude & "|"]
                Go To Record [ next ; exit after last ]
              End Loop
              Set FIeld [ YourTable::gLatLong ; Left ( YourTable::gLatLong ; Length(YourTable::gLatLong ) - 1 ] //strip off the extra "|"

              • 4. Re: How do I compile a URL that includes several latitude & longitude pairs?
                morgannews

                Phil, thanks.

                The script won't compile properly, but I can't see why. Here's how FM 7's Help file describes the format of the script step...

                Set Field [<table::field>; <value or formula>]

                ... so it seems like your formatting is okay, but FM disagrees with us.

                In the lines that have the gLatLong variable, Filemaker 7 wants an operator instead of a semi-colon. For example...

                Set Field [YourTable::gLatLong ; "" ]

                ... enerates an error message when I try to compile it. FM wants an operator instead of the semi-colon. It stops at the semi-colon and highlights the rest of the calculation component. It's happy if I replace the ; with an = sign, for example, and compiles if I do. The same goes for all the other instances of gLatLong.

                I tried running the script with the = in place. It quickly looped through the found set, but the gLatLong field was empty when it finished.

                By the way my equivalent of the Set step would be, if it didn't require an operator: 

                ${Tree Inventory - Asset Management}::gLatLong ; ""

                I've defined gLatLong as a simple global text field. I originally defined the 'latitude' and 'longitude' fields, which hold different data per record, as numeric, so I switched them to text, but that didn't solve the problem of getting FM to accept the semi-colon.

                I also tried adding brackets, (curved) and [square] to both ends of the ' YourTable::gLatLong ; "" ' component, but that didn't work either, but for a different reason. Instead of asking for an operator, it complained that the number of brackets was uneven.

                Also, not that it makes a different to me, because I just switched it up when I tried out your script, but Google's URL API requires the latitude first, the longitude second for each pair.

                You had mentioned earlier that you had a portal solution in mind. If you wanted to go the portal route, I'm game to follow.

                --

                You had asked earlier about the reason for the 10 lat/long pairs. I believe that's the maximum number of pairs Google Map's static map API will take in a URL, without getting into sophisticated Javascript programming. I was going to test that understanding once I got the script going. For my purposes, most of the time 10 will be sufficient, and I can always do a second or third map with the next set of 10 if need be. It's no big whoop.


                • 5. Re: How do I compile a URL that includes several latitude & longitude pairs?
                  philmodjunk

                  Don't enter the semil colon. FileMaker adds that for you.

                  You have two specify buttons. Click the first to select the field named to the left of the semi-colon. Click the lower, second specify button and enter the expression to the right of the semi-colon.

                  • 6. Re: How do I compile a URL that includes several latitude & longitude pairs?
                    morgannews

                    Ah! Thanks for the tip!

                    Your script works like a charm, Phil. Thank you so much for your insight, your script and your patience. And, I learned still more about FM Pro.

                    And, should you or others be interested, in testing Phil's script with my FM Pro database, I discovered that a Google Maps URL can take up to 62 lat/long pairs in displaying specific locations on one of its map, not 10 as I originally believed.

                    If anybody is interested in how the front part of such a URL is formed, please contact me off list. No JavaScript is required and Google Maps does not require an API key for this use, provided your usage is not heavy.

                    • 7. Re: How do I compile a URL that includes several latitude & longitude pairs?
                      philmodjunk

                      And with later versions of FileMaker, your method could be used with a web viewer--a widget that acts as a "mini browser" on your layout to display google map with the lat and long coordinates.