1. Go to this page and download the library: Download topukhan/geokit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
topukhan / geokit example snippets
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());
}
}
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
}
use Topukhan\Geokit\Contracts\GeocodingDriverInterface;
class GoogleGeocoder implements GeocodingDriverInterface
{
public function getName(): string
{
return 'google';
}
// Implement other interface methods...
}