topukhan/geokit is a Laravel package for a clean and extensible geocoding toolkit for laravel.
It currently has 0 GitHub stars and 4 downloads on Packagist (latest version v2.0.0).
Install it with composer require topukhan/geokit.
Discover more Laravel packages by topukhan
or browse all Laravel packages to compare alternatives.
Last updated
A clean and extensible geocoding toolkit for Laravel that supports multiple providers with automatic fallback handling.
Install the package via Composer:
composer require topukhan/geokit
Publish the configuration file:
php artisan vendor:publish --tag=geokit-config
Add these variables to your .env file:
# Optional: Your Geoapify API key (if you have one)
GEOKIT_GEOAPIFY_KEY=your_geoapify_api_key_here
# Optional: Request timeout in seconds (default: 30)
GEOKIT_TIMEOUT=30
# Optional: Maximum results per search (default: 10)
GEOKIT_MAX_RESULTS=10
# Optional: User agent for API requests
GEOKIT_USER_AGENT="Your App Name/1.0"
The config/geokit.php file allows you to customize:
use Topukhan\Geokit\Facades\Geokit;
$response = Geokit::search('Tongi, Dhaka');
// Check if we got results
if ($response->hasResults()) {
echo "Found {$response->count()} results\n";
// Get the first result
$first = $response->first();
echo "Best match: {$first->formatted}\n";
echo "Coordinates: {$first->lat}, {$first->lng}\n";
echo "Provider: {$first->provider}\n";
// Access address components
if (isset($first->components['city'])) {
echo "City: {$first->components['city']}\n";
}
}
// Check if fallback was used
if ($response->usedFallback) {
echo "Used fallback providers\n";
}
// See which providers failed
if (!empty($response->failedProviders)) {
echo "Failed providers: " . implode(', ', $response->failedProviders) . "\n";
}
use Topukhan\Geokit\Services\AddressResolverService;
class LocationController extends Controller
{
public function search(Request $request, AddressResolverService $geokit)
{
$response = $geokit->search($request->input('query'));
return response()->json($response->toArray());
}
}
All searches return a GeocodeResponse object with this structure:
GeocodeResponse {
+query: string // Original search query
+results: array // Array of GeocodeResult objects
+usedFallback: bool // Whether fallback providers were used
+failedProviders: array // Names of providers that failed
}
Each result in the results array is a GeocodeResult object:
GeocodeResult {
+provider: string // Provider name (e.g., 'geoapify', 'nominatim')
+formatted: string // Full formatted address
+lat: float // Latitude
+lng: float // Longitude
+components: array // Address components (city, state, country, etc.)
}
{
"query": "Tongi, Dhaka",
"results": [
{
"provider": "geoapify",
"formatted": "Tongi, Gazipur District, Dhaka Division, Bangladesh",
"lat": 23.8896,
"lng": 90.3961,
"components": {
"city": "Tongi",
"district": "Gazipur District",
"state": "Dhaka Division",
"country": "Bangladesh",
"country_code": "BD"
}
}
],
"usedFallback": false,
"failedProviders": []
}
The package handles various error scenarios automatically:
To add a new geocoding provider:
GeocodingDriverInterfaceExample:
use Topukhan\Geokit\Contracts\GeocodingDriverInterface;
class GoogleGeocoder implements GeocodingDriverInterface
{
public function getName(): string
{
return 'google';
}
// Implement other interface methods...
}
This package is open-sourced software licensed under the MIT license.