Laravel Geocoding

Packages

September 30th, 2019

geocodio-laravel.jpg

Geocod.io the geocoding service created by Mathias Hansen has just released a PHP and Laravel library for integrating with the service. It includes geocoding, reverse geocoding, and data matching for US and Canadian addresses.

Here is an example:

1$response = Geocodio::geocode('1109 N Highland St, Arlington, VA');
2
3/*
4{
5 "input": {
6 "address_components": {
7 "number": "1109"
8 "predirectional": "N"
9 "street": "Highland"
10 "suffix": "St"
11 "formatted_street": "N Highland St"
12 "city": "Arlington"
13 "state": "VA"
14 "country": "US"
15 }
16 "formatted_address": "1109 N Highland St, Arlington, VA"
17 }
18 "results": array:2 [
19 0 => {
20 "address_components": {
21 "number": "1109"
22 "predirectional": "N"
23 "street": "Highland"
24 "suffix": "St"
25 "formatted_street": "N Highland St"
26 "city": "Arlington"
27 "county": "Arlington County"
28 "state": "VA"
29 "zip": "22201"
30 "country": "US"
31 }
32 "formatted_address": "1109 N Highland St, Arlington, VA 22201"
33 "location": {
34 "lat": 38.886672
35 "lng": -77.094735
36 }
37 "accuracy": 1
38 "accuracy_type": "rooftop"
39 "source": "Arlington"
40 }
41 1 => {
42 "address_components": {
43 "number": "1109"
44 "predirectional": "N"
45 "street": "Highland"
46 "suffix": "St"
47 "formatted_street": "N Highland St"
48 "city": "Arlington"
49 "county": "Arlington County"
50 "state": "VA"
51 "zip": "22201"
52 "country": "US"
53 }
54 "formatted_address": "1109 N Highland St, Arlington, VA 22201"
55 "location": {
56 "lat": 38.886665
57 "lng": -77.094733
58 }
59 "accuracy": 1
60 "accuracy_type": "rooftop"
61 "source": "Virginia Geographic Information Network (VGIN)"
62 }
63 ]
64}
65*/

Of course, this is just the basics and geocoding can be useful for a myriad of things while we are building applications. This could be everything from finding latitude/longitude, addresses, proper zip codes, timezones, or even Congressional information.

You can find out more details and try out the package from their Github repo and the first 2,500 lookups per day are free.

Filed in:

Eric L. Barnes

Eric is the creator of Laravel News and has been covering Laravel since 2012.