【问题标题】:codeIgniter google maps api V3 coordinatescodeIgniter google maps api V3 坐标
【发布时间】:2014-05-20 06:58:22
【问题描述】:

我使用从演示到位置人员geolocation map 的地图我的问题是我想将坐标保存到数据库但我不知道如何?

【问题讨论】:

  • 更确切地说,我的问题是我无法获得我不知道它们所在位置的坐标。

标签: codeigniter google-maps-api-3 geolocation


【解决方案1】:

使用 google 和 curl 对位置进行编码...这是我编写并在生产站点上使用的示例函数:

//$loc can be any kind of location from 555 street name, city, st, zip to just city, state, etc.

$loc = 'Austin, TX';    
function get_geo_loc($loc) {
          $string = str_replace (" ", "+", urlencode($loc));
           $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false";

           $ch = curl_init();
           curl_setopt($ch, CURLOPT_URL, $details_url);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
           $response = json_decode(curl_exec($ch), true);

           $lat = $response['results'][0]['geometry']['location']['lat'];
           $lng = $response['results'][0]['geometry']['location']['lng'];

          return array(
             'lat' => $lat,
             'lng' => $lng
          );
       }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 2012-06-09
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-04
    相关资源
    最近更新 更多