Fatal error in StringHelper.php when using cache block around loop
Increase the amount of memory available to PHP through memory_limit is one option.

Another option is to reduce the amount of data (and therefore memory) you're dealing with in one request.

You don't share what craft.locationAPI.fetchAllLocations() is actually doing, but if you're returning results as Craft models, there is a significant overhead (performance and memory-wise) doing that with large data sets in Craft 2.x.  You could look and return more primitive data structures.

Another alternative is to batch the results and retrieve them over multiple AJAX queries.