Grab data from url?

Tagged: 

Viewing 3 reply threads
  • Author
    Posts
  • January 14, 2019 at 10:26 AM #33427

    Steve Smith
    Participant

    Using the latest version on iPhone/iPad…

    Is it possible to have a field/button that grabs data from a particular url?

    For example, when the button is pushed, TF uses your position to look up and grab the current weather.

    This is the .xml weather feed for an example location:
    https://w1.weather.gov/xml/current_obs/KFFZ.xml

    This is the raw weather feed for an example location:
    https://w1.weather.gov/data/METAR/KFFZ.1.txt

    It is also possible to get the data via ftp or an api, example:
    http://samples.openweathermap.org/data/2.5/weather?zip=94040,us&appid=b6907d289e10d714a6e88b30761fae22

    api call via coordinates:
    http://samples.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=b6907d289e10d714a6e88b30761fae22

    Possible?

    January 14, 2019 at 7:44 PM #33430

    Brendan
    Keymaster

    Hi Steve,

    Sure, you can do that using the Script feature. You need to know a bit of JavaScript, but there are functions to get data from a URL.

    See the docs for the JavaScript API:

    https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api

    Also there’s a sample script on this page that shows you how to get JSON data from a URL:

    https://www.tapforms.com/help-mac/5.3/en/topic/scripts

    January 20, 2019 at 8:51 AM #33500

    Steve Smith
    Participant

    Question: how does the ‘script field ‘ know the gps coordinates of the phone? I have a Location field in the form already, can the script field use that? Or can the script grab the gps coordinates itself from the phones gps?

    Also, I cannot write code, a friend will be writing this script for me. I will send him the script page link you posted above, and he has already looked at the NOAA api documents. He does not have TF, will that be an issue?

    January 20, 2019 at 7:56 PM #33503

    Brendan
    Keymaster

    Hi Steve,

    You can access a Location field value from a Script field. The location field value will end up being a dictionary that you can reference like this:

    var location_field_id = 'fld....';
    var location_value = record.getFieldValue(location_field_id);
    var title = location_value['title'];
    var latitude = location_value['lat'];
    var longitude = location_value['lon'];
    
    // now you can do whatever you want with the values
    

    The script can only get the values from a Tap Forms field. It doesn’t have a way to get the geo location coordinates itself. So you just need to add a Location field to your form and then let Tap Forms get the location for you for that field. Or of course you can set it to whatever location you want. Now once you have the location value, then the script can get access to the data.

    Your friend will need Tap Forms because there are specific Tap Forms functions that he’ll need access to.

Viewing 3 reply threads

You must be logged in to reply to this topic.