geocoder-php/arcgis-online-provider
ArcGIS Online provider for the PHP Geocoder library. Adds geocoding and reverse geocoding via ArcGIS Online services, including support for authentication and provider configuration. Suitable for integrating ArcGIS address lookup into PHP apps.
Installation Add the provider to your Laravel project via Composer:
composer require geocoder-php/arcgis-online-provider
Ensure geocoder-php/geocoder is also installed (required dependency).
Basic Setup
Register the provider in your config/geocoder.php:
'providers' => [
'arcgis_online' => [
'key' => env('ARCGIS_ONLINE_API_KEY'),
'url' => env('ARCGIS_ONLINE_URL', 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer'),
],
],
First Use Case: Geocoding an Address
Use the Geocoder facade to query ArcGIS Online:
use Geocoder\Geocoder;
use Geocoder\Provider\ArcgisOnline\ArcgisOnlineProvider;
$geocoder = new Geocoder();
$results = $geocoder->geocode('1600 Pennsylvania Ave, Washington, DC');
dd($results->first()->getPosition());
Reverse Geocoding Convert coordinates to an address:
$results = $geocoder->reverse('40.7128° N, 74.0060° W');
dd($results->first()->getFormattedAddress());
Batch Processing
Use geocodeQuery() for bulk operations:
$query = $geocoder->query('New York, NY');
$results = $query->get();
Custom Provider Configuration Extend the provider for retries or custom headers:
$provider = new ArcgisOnlineProvider([
'key' => env('ARCGIS_API_KEY'),
'url' => env('ARCGIS_URL'),
'timeout' => 10,
'headers' => ['User-Agent' => 'MyApp/1.0'],
]);
Integration with Laravel Models
Add geocoding to a User model:
public function resolveAddressAttribute()
{
$results = $geocoder->geocode($this->address);
return $results->first()?->getFormattedAddress();
}
API Key Restrictions
Cache::remember()).Rate Limiting & Throttling
'timeout' => 60,
retry() in queries:
$query->retry(3, 1000); // Retry 3 times with 1s delay
URL & Endpoint Quirks
geocode.arcgis.com, but custom endpoints (e.g., enterprise ArcGIS) require explicit URL config.World_Street_Map) may return null for non-English addresses.Error Handling
try {
$results = $geocoder->geocode($request->address);
} catch (\Geocoder\Exception\UnsupportedOperationException $e) {
return back()->withError('Invalid address format');
}
Extension Points
ArcgisOnlineProvider::parse() to handle non-standard responses.$provider->setClient(new \GuzzleHttp\Client(['debug' => true]));
Environment-Specific Config
config() helper to switch providers dynamically:
$geocoder = new Geocoder();
$geocoder->registerProvider('arcgis_online', config('geocoder.providers.arcgis_online'));
How can I help you explore Laravel packages today?