예제 #1
0
 /**
  * Get a specific map post including proxity.
  *
  * @param WP      $wp Wordpress object.
  * @param integer $post_id Post ID.
  * @param float   $lat Latitude.
  * @param float   $lon Longitude.
  * @return boolean True if the request was handled.
  */
 private static function get_specific_map_post_with_proximity($wp, $post_id, $lat, $lon)
 {
     $post = get_post($post_id);
     if (!$post) {
         return false;
     }
     $user = get_userdata($post->post_author);
     $obj = array('ID' => $post->ID, 'post_title' => $post->post_title, 'author_id' => $post->post_author, 'display_name' => $user->display_name, 'post_date_gmt' => $post->post_date_gmt);
     $closest = null;
     $closest_dist = null;
     $locations = XMapsDatabase::get_map_object_locations($post->ID, 'map-object');
     $origin = new Point($lon, $lat);
     $origin->setSRID(XMAPS_SRID);
     foreach ($locations as $location) {
         $dest = geoPHP::load($location->location);
         $dist = XMapsGeo::distance($origin, $dest);
         if (null == $closest_dist || $dist < $closest_dist) {
             $closest = $dest;
             $closest_dist = $dist;
         }
     }
     $wkt = '';
     if (count($locations) > 0) {
         $obj->location_wkt = $locations[0]->location;
     }
     if (null != $closest) {
         $obj['distance'] = $closest_dist;
         $obj['bearing'] = XMapsGeo::bearing($origin, $closest);
         $obj['type'] = $closest->geometryType();
     }
     if (isset($wp->query_vars['user-id']) && isset($wp->query_vars['period'])) {
         $found = XMapsDatabase::has_post_been_found($post_id, $wp->query_vars['user-id'], $wp->query_vars['period']);
         if ($found) {
             $obj['found'] = $found;
         }
     }
     header('Content-Type: application/json');
     echo json_encode(array('data' => $obj, 'request' => '/' . $wp->request . '?' . $_SERVER['QUERY_STRING']));
     return true;
 }