Google지도 및 지오 코딩 (주소를 lang/lat 좌표로 변환)으로 게임하고 있습니다. 모든게 지금까지 잘 작동하고 파일과 구글 맵 서버에서 대답을 얻고있다 :JSON 객체 일부 가져 오기
$address = urlencode($address);
$url = "http://maps.google.com/maps/api/geocode/json?address={$address}&sensor=false";
$content = file_get_contents($url);
echo '<pre>';
print_r($content);
echo '</pre>';
포인트 나는 그 모든 정보가 필요하지 않습니다.
질문
가 어떻게이 JSON 객체의 일부만받을 마십시오? (예 :. 난 단지 'results'->'address_components'->'type' = 'country';
필요)
B 내가 반환 (구글)의 함량을 줄일 수 있습니다 내가 모든 것을 필요로하지 않는 한 어떻게 든 파일?
업데이트
내가 JSON 객체에 데이터의 일부를 추가해야합니다. 따라서 디코딩 & 인코딩은 에너지 손실 (이 시점에서) & 시간처럼 보입니다. 어떤 아이디어라도 XML 객체를 요청할 때 (더 빨리) 더 좋을까요? (. 객체의 최종 세트는 정말 성능에 대해 관심을 가져야하는 이유는 꽤 크다.)
Google지도지도 서버 (파일 내용)에서
예 JSON 응답 :
{
"results" : [
{
"address_components" : [
{
"long_name" : "28",
"short_name" : "28",
"types" : [ "street_number" ]
},
{
"long_name" : "Sellhorner Weg",
"short_name" : "Sellhorner Weg",
"types" : [ "route" ]
},
{
"long_name" : "Behringen",
"short_name" : "Behringen",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Bispingen",
"short_name" : "Bispingen",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Soltau-Fallingbostel",
"short_name" : "Soltau-Fallingbostel",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Niedersachsen",
"short_name" : "NDS",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Deutschland",
"short_name" : "DE",
"types" : [ "country", "political" ]
},
{
"long_name" : "29646",
"short_name" : "29646",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Sellhorner Weg 28, 29646 Bispingen, Deutschland",
"geometry" : {
"location" : {
"lat" : 53.118080,
"lng" : 9.966859999999999
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 53.11942898029150,
"lng" : 9.96820898029150
},
"southwest" : {
"lat" : 53.11673101970850,
"lng" : 9.965511019708496
}
}
},
"partial_match" : true,
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
원하는 부분에 액세스 한 다음 해당 하위 배열을 사용하여 새 파일을 작성하십시오. – mario
파트 B는 실제로 googles API에 관한 것이므로 별도의 질문이거나 googlemaps가되도록 제목을 변경해야합니다. –