Populate a Map at The Same Time as showing Posts via AJAX

It looks like you attached your localised script to the main script, but you don’t enqueue the main script, you enqueue gmap.

I also notice you use the legacy/antiquated Admin AJAX interface. Have you considered using the modern REST API interface instead?

Also consider that your AJAX should be returning raw data. By returning raw HTML instead, you open yourself to security issues, and limit the possibilities for caching. Fetch data then generate the markup in the browser using JS instead

Finally, you can’t call wp_localize_script( 'main', 'myAjax.locations', $results ); inside an AJAX response, it doesn’t make sense. Localising a script attaches that data if main is enqueued, but it doesn’t make sense to enqueue a script or style in an AJAX request as no scripts or styles get printed out ( you need a wp_head call for that, and those don’t belong in AJAX requests either ).

A work around would be to put it in a script tag and assign it to a variable on window, but then you would need special handling to execute that javascript on the browser side, making the prior mentioned security problem even worse.

So instead:

  • fetch raw data from the site, not HTML, ideally JSON encoded
  • generate the UI in javascript in the browser, don’t blindly accept arbitrary hunks of HTML generated by PHP

By doing those 2, most of your problems will be sidestepped entirely, your application will be faster, and your code will be safer.