Do shortcode that is inserted in a textarea is not displaying properly

You should be returning $location from get_location, instead of echoing it. Your function currently echos the location as soon as it runs, thereby outputting the result before the rest of the copy.

error code: 523