Get taxonomy that is attached to post with all its parents

You want get_ancestors(). This is pretty crude but…

$locations = get_the_terms( $post->ID, 'category' ); 
// var_dump($locations);
$pat="<a href="".site_url().'/location/%s">%s</a>';
foreach ( $locations as $location ) {
  printf($pat,$location->slug,$location->name);
  $anc = get_ancestors($location->term_id,'category');
  if (!empty($anc)) {
    foreach ($anc as $term) {
      $t = get_term_by( 'term_id', $term, 'category');
      printf($pat,$t->slug,$t->name);
    }
  }
  break; 
}