Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/Service/AddressService.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,28 @@ private function lookupAddressExternal($adr): array {

// we get rid of "post office box" field
$splitted_adr = explode(';', $adr);
if (count($splitted_adr) > 2) {
array_shift($splitted_adr);
}

// remove blank lines (#706)
$splitted_adr = array_filter(array_map('trim', $splitted_adr));
$query_adr = implode(', ', $splitted_adr);
// ADR in VCard is mandated to 7 fields
if (sizeof($splitted_adr) == 7) {
$query_adr_parts = [];
// This matches the nominatim query with the fields of 'ADR' in VCard
$query_key_part = ['','','street', 'city','state', 'postalcode', 'country'];
foreach ($query_key_part as $index => $query_key) {
if ($query_key !== '' && $splitted_adr[$index] !== '') {
$query_adr_parts += $query_key . '=' . urlencode($splitted_adr[$index]);
}
}

$query_adr = implode(';', $query_adr_parts);
} else {
// Try to do our best with a naive query
$query_adr = 'q=' . urlencode(implode(', ', $splitted_adr));
}


$result_json = @file_get_contents(
'https://nominatim.openstreetmap.org/search.php?q=' . urlencode($query_adr) . '&format=jsonv2',
'https://nominatim.openstreetmap.org/search?format=jsonv2&' . $query_adr,
false,
$context
);
Expand Down
Loading