Best way to sort posts with different types by distance

OK, I added distance as custom field to allow me order them using wp_query orderby method!

 function    add_distance_as_customfield($posts){

       $longDest = $_GET['lng'];
                    $latDest = $_GET['ltd'];
      foreach ($posts as $post) {
           $placeLocation= get_field('location',$post->ID);
                               $longPlace =$placeLocation['lng'];

                         $latPlace = $placeLocation['lat'];
                         $distance=getDistance($latDest,$longDest,$latPlace,$longPlace);

                         if ( ! add_post_meta($post->ID, "distance", $distance,true ) ) { 
   update_post_meta( $post->ID, "distance", $distance );
}

      }
 }