我为我的框架使用Codeigniter,并且我已经去了文档,我还没有找到解决方案。追加变量到每个结果
既然我已经从数据库中选择了数据,我需要在每个检索到的记录末尾显示距离。
Example of json: {"details":[{"country":"United States","_id":"3892","lat":"39.954559","lng":"-82.837608","admin_level_1":"Ohio","locale":"Columbus"}]}
这是它需要的,请记住,距离不在数据库中,它是在飞行中计算的。
Example of json: {"details":[{"country":"United States","_id":"3892","lat":"39.954559","lng":"-82.837608","admin_level_1":"Ohio","locale":"Columbus", "distance": "1.2 Mi"}]}
任何关于如何获得距离的距离被追加到每个结果的末尾?
$dbStations->select('lat');
$dbStations->select('lng');
$dbStations->select('_id');
$stations = $dbStations->get('stDetails');
foreach ($stations->result() as $station) {
$lat2 = $station->lat;
$lng2 = $station->lng;
$stId = $station->_id;
$distance = $this->distance->gpsdistance($lat1, $lng1, $lat2, $lng2, "M");
if ($distance <= $rad) {
//at this point the code has determined that this id is within
//the preferred distance.
$stationArr[] = $stId;
}
}
$dbStations->select('country, _id, lat, lng, admin_level_1, locale');
$dbStations->where_in('_id', $stationArr);
$stations = $dbStations->get('stationDetails');
echo json_encode(array('stations' => $stations->result()));
}
'dbStations-> get('stDetails')''''dbStations-> get('stationDetails')'应该查询同一个表吗? – birderic