Postal Code Lookup

Morfik's Placename Lookup Package provides the interface to the Web Service that returns a list of places for a given postal code.


package-view.png
package-down.png


A Quick Walkthrough

To use Morfik's Placename Lookup Package, add the package to the project by using the ‘Used Packages’ command on the project ribbon (see Figure 1), or drag the package file onto the application main client area.


security-fig1.png
Figure 1: Used Packages Command


To use it in your code, first you have to add mfk_pcMain to the ‘Uses’ section of your module. Then you can use the TPostalCodeInfo class like this:


FX Code

...    
    PostalCodeInfo := TPostalCodeInfo.Create;
    PostalCodeInfo.Country := 'US';
    PostalCodeInfo.PostalCode := '94109';
    PostalCodeInfo.Callback   := GetMethodPointer(Self, @HandlePostalCode);
    PostalCodeInfo.Execute;
...
Procedure HandlePostalCode(CompletedAddresses : TArray);
Var
    i : Integer;
    Place : TPlace;
Begin
    ComboBox1.Clear;
    For i := 0 To CompletedAddresses.Count - 1 Do
    Begin
        Place := CompletedAddresses[i];
        ComboBox1.Add(Place.countryCode +'  '+ Place.postalcode +'  '+ Place.placeName);
    End;
    ComboBox1.DropDown;
End;


The code above will put one item into the combobox: “San Francisco”. If the same postal code is being used for several locations, the CompletedAddresses array contains more than one item.

If no information is available or the postal code is incorrect empty array is returned.

Note: Execute is an asynchronous method; it returns immediately. When the location information is retrieved the callback you provided gets called.
Note: Country is the country code according to ISO 3166. Please refer to http://www.iso.org/iso/english_country_names_and_code_elements for the complete list of country codes.

See Also

Back to top