Originally posted by xoggoth
View Post
<?php
$postcode_api_json_response = file_get_contents('https://api.getAddress.io/v2/uk/SE192BB/14/?api-key={my api-key}');
// Have to make sure it's UTF-8; it probably is, but the call to utf8_encode is a belt-&-braces thing
$postcode_api_data = json_decode(utf8_encode($postcode_api_json_response));
// Example: Turn the latitude and longitude into a string
$postcode_lat_lon = $postcode_api_data->Latitude . ',' . $postcode_api_data->Longitude;
// Example: Get the array of addresses into a separate variable
$addresses_for_postcode = $postcode_api_data->Addresses;
?>
<label for='postcode'>Postcode:</label>
<select name='postcode' id='postcode'>
<?php foreach $address in $addresses_for_postcode: ?>
<option><?= htmlspecialchars($address) ?></option>
<?php endforeach; ?>
</select>

Leave a comment: