|
1 |
| -# geocodefarm-php |
2 |
| -Geocode.Farm SDK for PHP |
| 1 | +# Geocode.Farm PHP SDK |
| 2 | + |
| 3 | +A lightweight, dependency-free PHP SDK for interacting with the [Geocode.Farm](https://geocode.farm) geocoding API. |
| 4 | + |
| 5 | +This SDK allows developers to easily perform **forward** (address to coordinates) and **reverse** (coordinates to address) geocoding using a simple object-oriented interface. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 📦 Installation |
| 10 | + |
| 11 | +You can install the SDK via [Composer](https://getcomposer.org): |
| 12 | + |
| 13 | +```bash |
| 14 | +composer require geocodefarm/geocodefarm-php |
| 15 | +``` |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## 🚀 Quick Start |
| 20 | + |
| 21 | +```php |
| 22 | +<?php |
| 23 | + |
| 24 | +require 'vendor/autoload.php'; |
| 25 | + |
| 26 | +use GeocodeFarm\GeocodeClient; |
| 27 | + |
| 28 | +// Initialize the client with your API key |
| 29 | +$client = new GeocodeClient('YOUR_API_KEY'); |
| 30 | + |
| 31 | +// Forward geocoding: address to lat/lon |
| 32 | +$response = $client->forward('30 N Gould St, Sheridan, WY'); |
| 33 | +print_r($response); |
| 34 | + |
| 35 | +// Reverse geocoding: lat/lon to address |
| 36 | +$response = $client->reverse(44.797773, -106.954918); |
| 37 | +print_r($response); |
| 38 | +``` |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## ✅ Response Format |
| 43 | + |
| 44 | +Both methods (`forward()` and `reverse()`) return an array like this on success: |
| 45 | + |
| 46 | +```php |
| 47 | +[ |
| 48 | + 'success' => true, |
| 49 | + 'status_code' => 200, |
| 50 | + 'lat' => 44.797773, |
| 51 | + 'lon' => -106.954918, |
| 52 | + 'accuracy' => 'EXACT_MATCH', |
| 53 | + 'full_address' => '30 N Gould St, Sheridan, WY 82801', |
| 54 | + 'result' => [ |
| 55 | + 'house_number' => '30', |
| 56 | + 'street_name' => 'N Gould St', |
| 57 | + 'locality' => 'Sheridan', |
| 58 | + 'admin_2' => 'Sheridan County', |
| 59 | + 'admin_1' => 'WY', |
| 60 | + 'country' => 'United States', |
| 61 | + 'postal_code' => '82801', |
| 62 | + 'formatted_address' => '30 N Gould St, Sheridan, WY 82801', |
| 63 | + 'latitude' => 44.797773, |
| 64 | + 'longitude' => -106.954918, |
| 65 | + 'accuracy' => 'EXACT_MATCH' |
| 66 | + ] |
| 67 | +] |
| 68 | +``` |
| 69 | + |
| 70 | +If an error occurs: |
| 71 | + |
| 72 | +```php |
| 73 | +[ |
| 74 | + 'success' => false, |
| 75 | + 'status_code' => 403, |
| 76 | + 'error' => 'API returned failure: INVALID_KEY' |
| 77 | +] |
| 78 | +``` |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## 📝 License |
| 83 | + |
| 84 | +This SDK is released under [The Unlicense](https://unlicense.org/) — public domain. Use it freely. |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## 🤝 Contributing |
| 89 | + |
| 90 | +Pull requests and issues are welcome! |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## 🌐 About |
| 95 | + |
| 96 | +For more information about the geocoding API, visit [https://geocode.farm](https://geocode.farm). |
0 commit comments