2

I need some type of PHP thingie so that I can input a few street-addresses
(such as: 123 Fake Street, Faketown, FA, 98765) and then it will give me the coordinates (latitude and longitude) of these addresses.
I need this to be completely dynamic (as I will be fetching these addresses from a DataBase).

Where can I find something that can do this?

Alec
  • 99
  • 2
  • 10

2 Answers2

4

The process of taking an address and turning it into lat/lng is called "Geocoding". I would look at the Google Geocode API.

https://developers.google.com/maps/documentation/geocoding/

user2588667
  • 480
  • 3
  • 10
2

I work for SmartyStreets, an address verification API provider. Our LiveAddress API does just what you need. New accounts can setup a free trial. Here's some sample PHP code:

<?php

// Customize this (get ID/token values in your SmartyStreets account)
$authId = urlencode("raw ID here");
$authToken = urlencode("raw token here");

// Address input
$input1 = urlencode("3785 s las vegs av.");
$input2 = urlencode("los vegas,");
$input3 = urlencode("nevada");

// Build the URL
$req = "https://api.smartystreets.com/street-address/?street={$input1}&city={$input2}&state={$input3}&auth-id={$authId}&auth-token={$authToken}";

// GET request and turn into associative array
$result = json_decode(file_get_contents($req),true);

echo "<pre>";
print_r($result);
echo "</pre>";

?>

What comes out looks like this:

{
    "input_index": 0,
    "candidate_index": 0,
    "delivery_line_1": "3785 Las Vegas Blvd S",
    "last_line": "Las Vegas NV 89109-4333",
    "delivery_point_barcode": "891094333992",
    "components": {
        "primary_number": "3785",
        "street_name": "Las Vegas",
        "street_postdirection": "S",
        "street_suffix": "Blvd",
        "city_name": "Las Vegas",
        "state_abbreviation": "NV",
        "zipcode": "89109",
        "plus4_code": "4333",
        "delivery_point": "99",
        "delivery_point_check_digit": "2"
    },
    "metadata": {
        "record_type": "H",
        "zip_type": "Standard",
        "county_fips": "32003",
        "county_name": "Clark",
        "carrier_route": "C024",
        "congressional_district": "01",
        "building_default_indicator": "Y",
        "rdi": "Commercial",
        "elot_sequence": "0119",
        "elot_sort": "A",
        "latitude": 36.10357,
        "longitude": -115.17295,
        "precision": "Zip9"
    },
    "analysis": {
        "dpv_match_code": "D",
        "dpv_footnotes": "AAN1",
        "dpv_cmra": "N",
        "dpv_vacant": "N",
        "active": "Y",
        "footnotes": "B#H#L#M#"
    }
}
Michael Whatcott
  • 5,603
  • 6
  • 36
  • 50
  • When you say "250 lookups per month," does that mean if 250 people come to my site and my site has 100 lookups, it will only work for 2.5 people? Or can my 100 lookups be viewed 250 times? What I'm doing is setting up maps with 100 locations already marked and visitors just view the locations. There aren't new locations added regularly, but the 100 that I have may increase over time. – Loko Web Design Sep 04 '15 at 17:43
  • Ok, in your case you would probably use 100 lookups and cache the results for as long as you are comfortable (address data can change). When you want to add other geocodes/addresses you would execute a request for each one and cache the result for display on your site. Most of our users allow their users to perform lookups in real-time, but it sounds like that's not necessary in your case. Just do the lookups behind the scenes and deploy cached results with your site. – Michael Whatcott Sep 04 '15 at 19:37