2014-04-07 3 views

답변

0

사용 구글과 위치를 인코딩 할 컬은 ... 여기 내가 작성하고 생산 현장에 지금 사용하고있는 한 예를 들어 함수이다 :

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