1. Hugh is now back at work, more or less full time, after a slower than expected recovery from his neck surgery early this month. Obviously we have a backlog of support to clear, and are working as hard as we can to take care of it. If you have an unanswered thread more than 3 days old, please post one (and only one) "bump" on it, to move it in to our "last 3 days" list. If you have an unanswered issue in a forum you no longer have access to due to subscriptions timing out, please use the Contact Us form, and provide us with the URL to the thread.

Calculating distance and writing to table

Discussion in 'Standard Support' started by pfleischman, Aug 8, 2011.

Thread Status:
Not open for further replies.
  1. pfleischman New Member

    Level: Community
    I found some great writeups on how to do this, but I'd like to work more seamlessly into a Fabrik form. I would assume it would have to be javascript that would run upon submission, pulling the variables and then writing the data to a field? Or would you recommend a different method?

    This seems like such an easy option to add to Google Maps Element if you're looking to beef that up.

    Example Javascript using two manually entered address into two form fields:
    Code (text):
    var geocoder, location1, location2;   function initialize() {   geocoder = new GClientGeocoder(); }   function showLocation() {     geocoder.getLocations(document.forms[0].address1.value, function (response) {       if (!response || response.Status.code != 200)       {           alert("Sorry, we were unable to geocode the first address");        }       else        {           location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};             geocoder.getLocations(document.forms[0].address2.value, function (response) {               if (!response || response.Status.code != 200)               {                   alert("Sorry, we were unable to geocode the second address");               }               else                {                   location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};                     calculateDistance();                }           });         }   }); }   function calculateDistance() {  try     {       var glatlng1 = new GLatLng(location1.lat, location1.lon);       var glatlng2 = new GLatLng(location2.lat, location2.lon);       var miledistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(1);        var kmdistance = (miledistance * 1.609344).toFixed(1);          document.getElementById('results').innerHTML = '<strong>Address 1: </strong>' + location1.address + '<br /><strong>Address 2: </strong>' + location2.address + '<br /><strong>Distance: </strong>' + miledistance + ' miles (or ' + kmdistance + ' kilometers)';    }   catch (error)   {       alert(error);   } }
  2. pfleischman New Member

    Level: Community
    Completely disregard what I just posted. I did more searching and realized you wrote the Radius Search Plugin.

    Just in case someone else is looking for this info:

    Radius Search Plugin
    http://fabrikar.com/wiki/index.php/Radius_search_table_plugin
    Version 2.1
    http://fabrikar.com/downloads/details/36/142
Thread Status:
Not open for further replies.

Share This Page