O'Reilly logo

Wicked Cool PHP by Brian Ward, William Steinmetz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

#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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required