Extend: Catch the first item in the results list


After store locator search results are received, you need to get hold of the first location coordinates.


Our locator plugin front end JavaScript code adds a few document events that can let you listen to or modify its behaviour. In this example we make use of locatoraid-get-results which fires when Locatorad returns the search results following the user search.

Your code may read something like this:

document.addEventListener( 'locatoraid-get-results', function(e){
  var results = e.payload.hasOwnProperty('results') ? event.payload.results : [];
  if( results.length > 1 ){
    var firstMatch = results[0];
    console.log( firstMatch['latitude'] );
    console.log( firstMatch['longitude'] );

There are several ways to make use of this additional JavaScript code:

  • Add the custom code to your theme JavaScript file.
  • Or just add the custom Javascript code directly to the content of the page with Locatoraid [locatoraid] shortcode. Do not forget to wrap the JavaScript code with the <script> and </script> tags.

Latest update: Version 3.9.8

Order Now

Get the Pro version for a lot more nice features.

Order Now