2
我正在嘗試從輸入帖子發佈的數據處理數組ip。爲了將它轉換爲緯度我使用下面的代碼經度,我無法將數組轉換爲經度和緯度
這是我的CI庫:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
include APPPATH . 'libraries/GeoIP/src/geoipcity.inc';
class GeoIp{
public function info($ip){
$gi = geoip_open(APPPATH . 'libraries/GeoIp/data/GeoLiteCity.dat', GEOIP_STANDARD);
$record = geoip_record_by_addr($gi, $ip);
geoip_close($gi);
return $record;
}
public function get($ip){
$gi = geoip_open(APPPATH . 'libraries/GeoIp/data/GeoLiteCity.dat', GEOIP_STANDARD);
$records = array();
$ips = is_array($ip);
foreach ($ips as $key=>$value) {
$records[] = geoip_record_by_addr($gi, $value);
}
foreach ($records as $record) {
$record_string = $record->longitude . "," . $record->latitude;
geoip_close($gi);
return $record_string;
}
}
}
這我的控制器:
public function iplat(){
$this->load->library('geoip');
$record = $this->geoip->get($this->input->post('ip'));
echo json_encode($record);
}
該代碼總是返回null
2的問題在我看來: - 1'$ GI = geoip_open(APPPATH '庫/ GEOIP /數據/ GeoLiteCity.dat',GEOIP_STANDARD); 「我認爲路徑問題在那裏。 '$ this-> load-> library('geoip');'你需要知道它工作正常與否。檢查你的錯誤日誌文件(我希望codeignitor產生錯誤日誌文件) –