dtbc37573 2017-02-14 19:54
浏览 35

如何在服务器上的同构应用程序中获取某个位置的经度和经度

I have isomorphic app which loads on server and client as well. My concern is about loading results for the application on server I need to call google maps api service to get lattitude and longitude for the place for ex 'www.mysite.com/search/New-York--NY--United-States' then I need to find its latitude and longitude from google maps api with below code in php(my api is in 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'];
            }

Then based on this latitude and longitude I search for my results as below

$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)));

With above code I calculate maximum and minimum lattitude and longitude and then look for my results by applying where conditions as below.

$this->db->where('rv.LATITUDE >=', $minlat);
$this->db->where('rv.LATITUDE <=', $maxlat);
$this->db->where('rv.LONGTITUDE >=', $minlng);
$this->db->where('rv.LONGTITUDE <=', $maxlng);

How to get latitude and longitude without calling google maps api and how to optimize it to get results faster. Please provide suggestions regarding this question.

  • 写回答

1条回答 默认 最新

  • douzhenchun6782 2017-02-14 21:07
    关注

    If you're not trying to pin down street addresses and only interested in discrete place names like cities, landmarks, etc (in your example, New York, USA) you might look into the various GeoNames exportables. You could load them into a local datastore and perform lookups by name.

    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)