Optimize the location search algorithm