GoogleMapsAPIȤνƤäꤹ롣
֥롼ݥʤȤ˻Ȥޤ
ñAPIáƤʤΤǥ٤ˡ

ε CakePHP۰־μȡ2֤εΥ׻ΥݡͥȤɲä⡣

Ȥ櫓ǡ

App/controllers/components/geo.php

class GeoComponent extends Object {
  public function addr2geo($addr=""){
    $url = sprintf("http://maps.google.co.jp/maps/geo?q=%s&output=json&key=%s",
                   urlencode($addr),
                   'GoogleMapsAPIKEY');
    $res = file_get_contents($url);
    $data = json_decode($res);
    $geo = $data->Placemark[0]->Point->coordinates;
    return array('lng' => $geo[0], 'lat' => $geo[1]);
  }
}
ǡǤʤäȤνӽ񤤤Ƥ͡

App/controllers/foo_controller.php

class FooController extends Controller {
  var $name = 'Foo';
  var $components = array('Geo');

  function index () {
    $addr = 'Կɶ迷ɻ38-1';
    $geo = $this->Geo->addr2geo($addr);
    echo $geo['lat']; //
    echo $geo['lng']; //
  }
}


־򥵡ӥ˻ȤȤ⤷͡
⤤äƤФʡ