내 프레임 워크에 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