#71: Using Mapping Web Services

At this point, you know how to access a URL and how to parse XML, so now it's time to put the two together. Let's look at the Yahoo! geocoding service as a simple example. The API is a REST service that you can access through GET parameters. Assuming that you have the retrieve_page() function from "#68: Connecting to Other Websites" on #68: Connecting to Other Websites, here's how to get information for a prominent address in Washington, D.C.

$qs = http_build_query(array(
    "appid"     => "YahooDemo",
    "street"    => "1600 Pennsylvania Avenue NW",
    "city"      => "Washington",
    "state"     => "DC",
    "zip"       => "20006",
));
$page = retrieve_page("http://local.yahooapis.com/MapsService/V1/
geocode?$qs");

Note

Ideally, you want to replace

Get Wicked Cool PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.