WordPress Store Locator Plugin

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: