<pre>
<?php
function
lookup(
$string
){
$string
=
str_replace
(
" "
,
"+"
, urlencode(
$string
));
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_URL,
$details_url
);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, 1);
$response
= json_decode(curl_exec(
$ch
), true);
// If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
if
(
$response
[
'status'
] !=
'OK'
) {
return
null;
}
print_r(
$response
);
$geometry
=
$response
[
'results'
][0][
'geometry'
];
$longitude
=
$geometry
[
'location'
][
'lat'
];
$latitude
=
$geometry
[
'location'
][
'lng'
];
$array
=
array
(
'latitude'
=>
$geometry
[
'location'
][
'lat'
],
'longitude'
=>
$geometry
[
'location'
][
'lng'
],
'location_type'
=>
$geometry
[
'location_type'
],
);
return
$array
;
}
$city
=
'San Francisco, USA'
;
$array
= lookup(
$city
);
print_r(
$array
);
?>
</pre>
'PHP' 카테고리의 다른 글
[php] curl (0) | 2014.08.28 |
---|---|
[php] 리다이렉션(페이지 이동) 방법 (0) | 2014.08.26 |
php 접속 경로 확인 리퍼러(referer) (0) | 2014.07.01 |
WRITTEN BY
- rabbbit
필기
,