1. We apologize for the slow support at the moment. Hugh (cheesegrits) is scheduled for some major back surgery this month to repair two ruptured discs which are severely hampering his ability to work, and one of our stalwart community support members is on vacation for the month. Please bear with us.

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