我正在尝试从输入帖子发布的数据中处理数组 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