2

我需要某种类型的 PHP 东西,这样我就可以输入一些街道地址
(例如:123 Fake Street, Faketown, FA, 98765),然后它会给我这些地址的坐标(纬度和经度)。
我需要它是完全动态的(因为我将从数据库中获取这些地址)。

我在哪里可以找到可以做到这一点的东西?

4

2 回答 2

4

获取地址并将其转换为 lat/lng 的过程称为“地理编码”。我会看看 Google Geocode API。

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

于 2013-08-16T21:29:41.950 回答
2

我为地址验证 API 提供商 SmartyStreets 工作。我们的LiveAddress API 可以满足您的需求。可以免费设置一个帐户,每月可进行 250 次查找。这是一些示例 PHP 代码

<?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>";

?>

出来的结果是这样的:

{
    "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#"
    }
}
于 2013-08-16T23:55:28.517 回答