나는 구글 지오 코딩 API를 사용하고 있습니다를 사용하여 XML 결과에서 모든 필드의 압축을 풉니 다. 아래의 코드는 어레이 $arrGeocodeSales
통해 반복하고, 각 행에 대해 그 다음 표에 표시되는 $lat
및 $long
를 검색한다.구체적으로 XML 출력 형식에 의존, 구글 지오 코딩 API
이 코드는 정상적으로 작동하지만 반환 할 결과가 $xml
인 결과에서 더 많은 필드를 추출 할 수 있도록 확장하고 싶습니다. 예를 들어 $ xml 결과에서 추출하려는 추가 필드 중 일부는 formatted_address
및 postal_code
입니다. 아래의 코드를 수정하여 추가 필드를 추출하려면 어떻게해야합니까?
당신은 여기 $의 XML 결과의 예를 볼 수 있습니다 여기에
수정해야하는 코드입니다. 나는 반환 된SimpleXMLElement
을 사용하는 방법을 이해하지 못한다고 생각합니다. 도와 주셔서 감사합니다.
<table border="1" style="margin-bottom:0px;">
<tr>
<th>ID</th>
<th>Roll</th>
<th>Address</th>
<th>Lat</th>
<th>Long</th>
<th>MapSaleNumber</th>
</tr>
<?php foreach ($arrGeocodeSales as $key => $value):
$address = $value['Address']."+".$value['Municipality']."+Ontario+Canada";
$googleAddress = "https://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml";
// Retrieve the URL contents
$googlePage = file_get_contents($googleAddress);
// Parse the returned XML file
$xml = new SimpleXMLElement($googlePage);
// Parse the coordinate string
list($lng, $lat, $alt) = explode(",", $xml->Response->Placemark->Point->coordinates);
?>
<tr>
<td ><?php echo str_pad($row++, 2, '0', STR_PAD_LEFT); ?></td>
<td ><?php echo $value['SingleRoll']; ?></td>
<td ><?php echo $address; ?> </td>
<td ><?php echo $lat ?></td>
<td ><?php echo $lng ?></td>
<td ><?php echo $value['MapSaleNumber']; ?></td>
</tr>
<?php endforeach; ?>