Jump to content
  • 0

Lookup geo lat/long for map search




I have the need to search a directory of service providers. In the directory I have the lat/long of each provider in two fields (geo_lat, geo_long).  I have another table that is "cities". In there, the center of each city is also coded with geo_lat and geo_long.  I want to have a user be able to type in the name of a city and have it lookup the geo_lat and geo_long of that city and use them in a radius search of the service provider directory.

I cannot use addresses or zip codes because we are a confidential hotline that does not collect that type of information for safety purposes.  I can do the lookup of the city and find the lat/long values, but I don't know how to pass them to the Distance Search Center Lat and Center Long fields.  Suggestions?

In my searching around I thought that by using this snippet of code in an HTML block it might work. The idea is that the Virtual4 field is populated with the latitude of the city and the Virtual5 field is populated with the longitude of the city.  I am then trying to set the value of the 2 distance search fields (cbDSField1 and cbDSField2) to those two values.  I am using the onchage trigger instead of on-submit in the hopes I would be able to see the values populate in all four fields.  It just isn't working.  What am I doing wrong???



function searchGeo()

let search_lat = document.getElementByID('cbParamVirtual4').value;

document.getElementByID('InsertRecordcbDSField1').value = search_lat;

let search_long = document.getElementByID('cbParamVirtual5').value;

document.getElementByID('InsertRecordcbDSField2').value = search_long;

document.getElementById('caspioform').onchange = searchGeo;


Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @mhand,

You may try to use the following JavaScript snippet:

document.addEventListener('DataPageReady', eventHandler);

function eventHandler(){

document.querySelector('input[name="cbParamVirtual4"]').addEventListener('change', copyFields);
document.querySelector('input[name="cbParamVirtual5"]').addEventListener('change', copyFields);


function copyFields(e){

   const element = e.target.name;
   if(element === "cbParamVirtual4"){

      document.querySelector('#cbDSField1').value = e.target.value;

   } else if (element === "cbParamVirtual5") {
      document.querySelector('#cbDSField2').value = e.target.value;




Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...