How do I populate zip-based city / state fields?

I know there are databases for zip codes, but how can I capture city / state fields based on this? Do these databases have a city / state or do I need to do some kind of search in a web service?

+3
source share
5 answers

\ start {-was done there that}

Important implementation: there is no one-to-one mapping between cities / counties and postal codes. The postal code is not based on a political area, but instead is a distribution area defined for internal USPS use. It makes no sense to search for a city based on a zip code if you do not have +4 or the entire street address to match the entry in the USPS address database; otherwise you won’t know if there is RICHMOND or HENRICO, DALLAS or FORT WORTH; there is not enough information to tell.

, , , - , , ( , ) - .

USPS , , , , USPS, .

, ( ) . , , , , ; . ASHLAND, 7 . ASHLAND , .

-, , City/State/ZIP, , , . ? .

, !

\ {- , }

+6

API HTTP/XML

- , -API XML, 4.0 (. 22) PDF-, URL-, XML-, 5- , XML-, .

, :

http://SERVERNAME/ShippingAPITest.dll?API=CityStateLookup&XML=<CityStateLookupRequest%20USERID="xxxxxxx"><ZipCode ID= "0"><Zip5>90210</Zip5></ZipCode></CityStateLookupRequest>

:

<?xml version="1.0"?> 
<CityStateLookupResponse> 
    <ZipCode ID="0"> 
        <Zip5>90210</Zip5> 
        <City>BEVERLY HILLS</City> 
        <State>CA</State> 
    </ZipCode> 
</CityStateLookupResponse>

USPS , , API, , , . , API : , , , ..

+1

Ziptastic API HTTP/JSON

, , , , , GET http://ziptasticapi.com, :

GET http://ziptasticapi.com/48867

JSON :

{"country": "US", "state": "MI", "city": "OWOSSO"}

, . , - :

curl http://ziptasticapi.com/48867 
+1

" ...", " ..."

, , . , , (. Pentium10 ). , ZIP /. , ZIP, .

ZIP ( sourceforge):

"zip code", "state abbreviation", "latitude", "longitude", "city", "state"
"35004", "AL", " 33.606379", " -86.50249", "Moody", "Alabama"
"35005", "AL", " 33.592585", " -86.95969", "Adamsville", "Alabama"
"35006", "AL", " 33.451714", " -87.23957", "Adger", "Alabama"

$zipLine = lookup($ZIP);
if($zipLine) {
    $fields = explode(", ", $zipLine);
    $city  = $fields[4];
    $state = $fields[5];
}  else {
    die "$ZIP not found";
}

If you just play with text in PHP, that’s all you need. But if you have a database application, you would do everything in SQL. More detailed information about your application may be caused by more detailed answers.

0
source

Source: https://habr.com/ru/post/1733255/


All Articles