Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Here Provider Laravel Package

geocoder-php/here-provider

HERE provider for the Geocoder PHP library. Adds forward and reverse geocoding via HERE APIs, returning consistent Geocoder results for addresses, places, and coordinates. Intended for use with geocoder-php adapters and your HERE credentials.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require geocoder-php/here-provider
    

    Ensure geocoder-php/geocoder is also installed (required dependency).

  2. First Use Case: Reverse Geocoding

    use Geocoder\Geocoder;
    use Geocoder\Provider\Here\HereProvider;
    
    $geocoder = new Geocoder();
    $geocoder->registerProvider(new HereProvider('YOUR_HERE_API_KEY'));
    
    $result = $geocoder->reverseQuery('52.5170365,13.3888601');
    dd($result->getCoordinates(), $result->getDescription());
    
  3. Where to Look First

    • Provider Documentation (core Geocoder package)
    • Here API Docs (for rate limits, response formats, and edge cases)
    • HereProvider class source: Focus on query(), reverseQuery(), and geocodeQuery() methods.

Implementation Patterns

Common Workflows

  1. Geocoding (Address → Coordinates)

    $result = $geocoder->geocodeQuery('100 Broadway, New York, NY');
    $coordinates = $result->getCoordinates(); // [lat, lng]
    
  2. Reverse Geocoding (Coordinates → Address)

    $result = $geocoder->reverseQuery('52.5170365,13.3888601');
    $address = $result->getDescription(); // "Brandenburg Gate, Berlin, Germany"
    
  3. Batch Processing

    $addresses = ['100 Broadway', '221B Baker St'];
    $results = $geocoder->batchGeocodeQuery($addresses);
    
  4. Fallback Providers

    $geocoder->registerProvider(new HereProvider('API_KEY'));
    $geocoder->registerProvider(new \Geocoder\Provider\GoogleMaps\GoogleMapsProvider('GOOGLE_API_KEY'));
    $result = $geocoder->geocodeQuery('Invalid Address'); // Falls back to Google if Here fails.
    

Integration Tips

  • Caching Responses Use Laravel’s cache to avoid hitting API limits:

    $cacheKey = 'here_geocode_' . md5($address);
    $result = Cache::remember($cacheKey, now()->addHours(1), function () use ($geocoder, $address) {
        return $geocoder->geocodeQuery($address);
    });
    
  • Rate Limiting Here’s API has strict limits (e.g., 100,000 requests/month for free tier). Log requests and monitor usage:

    $geocoder->registerProvider(new HereProvider('API_KEY', [
        'logger' => new \Monolog\Logger('here'),
    ]));
    
  • Customizing HTTP Client Override the default Guzzle client for retries/timeouts:

    $client = new \GuzzleHttp\Client([
        'timeout' => 10,
        'connect_timeout' => 5,
    ]);
    $provider = new HereProvider('API_KEY', ['client' => $client]);
    

Gotchas and Tips

Pitfalls

  1. API Key Restrictions

    • Here’s API keys are tied to specific domains. Test in a staging environment first.
    • Fix: Use a wildcard (*) in the allowed domains during development, then restrict to production domains.
  2. Response Parsing Errors

    • Here’s API returns nested JSON. Malformed responses (e.g., missing items array) can break parsing.
    • Debug: Check the raw response with:
      $provider->getClient()->getConfig('debug');
      
  3. Coordinate Order

    • Here’s API returns [longitude, latitude] by default, but Geocoder expects [latitude, longitude].
    • Workaround: Use Geocoder\Provider\Normalizer\Normalizer to standardize coordinates.
  4. Rate Limit Headers

    • Ignoring X-RateLimit-* headers can lead to sudden API failures.
    • Tip: Log headers and implement exponential backoff:
      $response = $provider->getClient()->request('GET', $url);
      $remainingRequests = $response->getHeader('X-RateLimit-Remaining')[0];
      

Debugging

  • Enable Debug Mode

    $provider = new HereProvider('API_KEY', ['debug' => true]);
    

    Logs raw requests/responses to storage/logs/geocoder.log.

  • Common HTTP Errors

    Error Code Cause Solution
    401 Invalid API key Regenerate key in Here’s Developer Portal.
    403 IP/domain not whitelisted Update allowed domains in API settings.
    429 Rate limit exceeded Wait or upgrade plan.
    500 Internal server error Retry with exponential backoff.

Extension Points

  1. Custom Response Normalization Extend HereProvider to handle non-standard responses:

    class CustomHereProvider extends HereProvider {
        protected function parseResponse($data) {
            // Override to handle custom Here API response formats.
        }
    }
    
  2. Adding Custom Fields Extract additional fields from Here’s response (e.g., houseNumber, postalCode):

    $result = $geocoder->reverseQuery('52.5170365,13.3888601');
    $address = $result->getAddress();
    $postalCode = $address->getPostalCode(); // Default
    $houseNumber = $data['items'][0]['result']['address']['houseNumber']; // Custom
    
  3. Mocking for Tests Use a mock HTTP client to avoid real API calls:

    $mockHandler = new \GuzzleHttp\Handler\MockHandler([
        new \GuzzleHttp\Psr7\Response(200, [], file_get_contents('tests/fixtures/here_response.json'))
    ]);
    $client = new \GuzzleHttp\Client(['handler' => $mockHandler]);
    $provider = new HereProvider('API_KEY', ['client' => $client]);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor