maps icon indicating copy to clipboard operation
maps copied to clipboard

Fix extended addresses preventing contact map location matches

Open Copilot opened this issue 3 months ago • 2 comments

Contacts with extended addresses (apartment numbers, suite numbers, etc.) were not showing up on the map due to geocoding failures. The issue was in the address processing logic within AddressService::lookupAddressExternal().

Problem

The vCard ADR format uses semicolon-separated fields:

post-office-box;extended-address;street-address;locality;region;postal-code;country-name

For example:

;Apt 1;150 West 95th Street;New York;NY;10025;

The existing code only removed the post office box (field 0) but kept the extended address (field 1), resulting in geocoding queries like:

"Apt 1, 150 West 95th Street, New York, NY, 10025"

These queries often fail with geocoding services like Nominatim because apartment numbers make the address too specific or ambiguous.

Solution

Enhanced the address processing to remove both the post office box (field 0) AND the extended address (field 1) from geocoding queries:

// Before
array_shift($splitted_adr); // Remove post office box only

// After  
array_shift($splitted_adr); // Remove post office box (field 0)
if (count($splitted_adr) > 1 && trim($splitted_adr[0]) !== '') {
    array_shift($splitted_adr); // Remove extended address (field 1)
}

Now the same address produces a clean geocoding query:

"150 West 95th Street, New York, NY, 10025"

Impact

  • Contacts with apartment numbers, suite numbers, etc. now appear on the map
  • The original contact data is preserved - only the geocoding query is cleaned
  • Backward compatible with addresses that don't have extended address fields
  • Improves geocoding success rate for residential addresses

Fixes #712.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/Bogdaan/open-location-code/zipball/6e384e41cc6d6dd4d87f95c36aabf0de5256bf3f
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/eea219a577085bd13ff0cb644a422c20798316c7
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • https://api.github.com/repos/bamarni/composer-bin-plugin/zipball/92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • https://api.github.com/repos/kubawerlos/php-cs-fixer-custom-fixers/zipball/93222100a91399314c3726857e249e76c4a7d760
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • https://api.github.com/repos/nextcloud/coding-standard/zipball/9c719c4747fa26efc12f2e8b21c14a9a75c6ba6d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • https://api.github.com/repos/pel/pel/zipball/b95fe29cdacf9d36330da277f10910a13648c84c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/RHb0xQ /usr/bin/composer install --no-dev (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/Eav9mG /usr/bin/composer install --no-interaction --ignore-platform-reqs (http block)
  • nominatim.openstreetmap.org
    • Triggering command: php /tmp/test_geocoding.php (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Sep 04 '25 09:09 Copilot

@tacruc 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot avatar Sep 04 '25 09:09 Copilot

Does it work on non US Based addresses too.

tacruc avatar Sep 08 '25 09:09 tacruc