latitude
嗨,我正在尝试longitude
通过address
function get_lat_long_from_address($address)
{
$lat = 0;
$lng = 0;
if ($this->geocodeCaching) { // if caching of geocode requests is activated
$CI =& get_instance();
$CI->load->database();
$CI->db->select("latitude,longitude");
$CI->db->from("geocoding");
$CI->db->where("address", trim(strtolower($address)));
$query = $CI->db->get();
if ($query->num_rows()>0) {
$row = $query->row();
return array($row->latitude, $row->longitude);
}
}
$data_location = "http://maps.google.com/maps/api/geocode/json?address=".str_replace(" ", "+", $address)."&sensor=".$this->sensor;
if ($this->region!="" && strlen($this->region)==2) { $data_location .= "®ion=".$this->region; }
$data = file_get_contents($data_location);
$data = json_decode($data);
if ($data->status=="OK") {
$lat = $data->results[0]->geometry->location->lat;
$lng = $data->results[0]->geometry->location->lng;
if ($this->geocodeCaching) { // if we to need to cache this result
$data = array(
"address"=>trim(strtolower($address)),
"latitude"=>$lat,
"longitude"=>$lng
);
$CI->db->insert("geocoding", $data);
}
}
return array($lat, $lng);
}
问题是我传递给函数的任何地址,它只返回(0,0)
纬度和经度。
我通过了地址
$address = "colombo,sri lanka";
$address = "colombo,LK";
$address = "newyork,United states";
$address = "1/35 amunugama gunnena,kandy,sri lanka";
但每次回来(0,0)
,
这是为什么,我需要使用什么地址格式,请帮忙。提前致谢 .........