Rounds a decimal to its nearest whole number



Zephyr: {round(50.5)} = 51

Display Content from a Feed Based on a User’s Geolocation

Use Case: You’re using the sailthru.location meta tag to place latitude and longitude on your content, and you want to only display content if the user is geo-located within 20 miles of that item.


{**Creates an array of user lat/long, coords[0] being lat, coords[1] being long**}
{coords = user_geo_home("coordinates")}
Stories in Your Neighborhood:
{foreach content as c}
  {if contains(c,c.location)}
      {if distance(c.location[0], c.location[1], coords[0], coords[1]) > 20}
<a href="{c.url}">{c.title}<a/> ({round(distance(c.location[0],c.location[1],coords[0],coords[1]))} from you!) <br/>


Stories in Your Neighborhood:

(New York City based user):

Get Your First Look at the New iPhone at the Times Square Apple Store (2.1 miles you from!)

Spider-Man: Threat or Menace? (7.2 miles from you!)

(Los Angeles based user):

Alexander Harris elected to Los Angeles House of Representatives (12.8 miles from you!)


This script uses the user_geo_home() function to find the coordinates of a user’s Sailthru-tracked geolocation (obtained at point of click through an email). It then assigns this value to a local variable called “coords,” which is an array of the user latitude (position 0) and longitutde (position 1). Next, a foreach loop iterates through each piece of content from a data feed and, using an “if statement”, uses the contains() function to see if each content has the “location” parameter. If it does, using a second “if” statement, the script uses the distance() function to check if if the content’s latitude/longitude (c.location[0] and c.location[1] is within the user’s latitude/longitude (coords[0] and coords[1]. If the statement evaluates to true, the title and URL will populate and display to the user.

The script also uses the round() function to tell the user how close they are from the story. The distance from the user is calculated the same as before (using the item’s coordinates evaluated against the user’s), but the actual distance is rounded to the nearest decimal point in order to display a user-friendly version of how close the user is.