我有同构的应用程序,加载在服务器和客户端以及。我关心的是在服务器上加载应用程序的结果,我需要调用谷歌地图api服务来获取ex 'www.mysite.com/search/New-York--NY--United-States‘地点的经度和纬度,然后我需要用php中的以下代码从google map api中找到它的纬度和经度(我的api是用php编写的)
$address= $this->input->get('address');
$geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');
$geo = json_decode($geo, true);
if ($geo['status'] = 'OK') {
$lat = $geo['results'][0]['geometry']['location']['lat'];
$lng = $geo['results'][0]['geometry']['location']['lng'];
}然后根据这个纬度和经度搜索我的结果,如下所示
$radius = 6371;
$distance = 250;
// latitude boundaries
$maxlat = $lat + rad2deg($distance / $radius);
$minlat = $lat - rad2deg($distance / $radius);
// longitude boundaries (longitude gets smaller when latitude increases)
$maxlng = $lng + rad2deg($distance / $radius / cos(deg2rad($lat)));
$minlng = $lng - rad2deg($distance / $radius / cos(deg2rad($lat)));使用上面的代码,我计算了最大和最小纬度和经度,然后通过应用where条件来查找结果,如下所示。
$this->db->where('rv.LATITUDE >=', $minlat);
$this->db->where('rv.LATITUDE <=', $maxlat);
$this->db->where('rv.LONGTITUDE >=', $minlng);
$this->db->where('rv.LONGTITUDE <=', $maxlng);如何在不调用google地图api的情况下获得纬度和经度,以及如何对其进行优化以更快地获得结果。请提供有关此问题的建议。
发布于 2017-02-15 05:07:25
如果您不想确定街道地址,并且只对离散的地名感兴趣,如城市、地标等(在您的示例中,纽约,美国),您可以查看各种GeoNames exportables。您可以将它们加载到本地数据存储中,并按名称执行查找。
https://stackoverflow.com/questions/42235025
复制相似问题