Understanding How to Use Open XML Data Sources in PHP

Modern web programming relies upon connecting to quality external data sources to populate your site. There’s no reason to reinvent the wheel when organizations such as Google and Yelp have compiled impressive, open sources of data you can pull into your site.

API (or Application Protocol Interface) allows you to interact with third party applications, libraries and data to extend your own web app.  Most commonly, APIs take the form of HTTP protocols to pull in data through XML or Javascript (JSON) functions. There are a variety of ways you to implement common API data on your site such as Flickr photos, Twitter feeds and a variety of data from specialized sites.

The best part of any API is that it makes it substantially easier to populate an early site – you don’t have to wait for thousands of consumer reviews or registrations before you can begin filling out your framework. In fact, there are entire sites built as “mash ups” of other data in creative ways, such as Friend Feed which allows users to interact with a variety of social accounts.  While APIs are used generally for sharing programming libraries including Open GL for graphics, web-based APIs have enabled information sharing and application development with relative ease.

Starting to Pull in Data from Google Maps

One common data source used by many sites is Google Maps, which aggregates location information, business contacts and reviews from Google. You can create anything from a business directory to a dynamic contact us feature within your application depending on your goals.  Google has built out an easy framework that allows you to build out local databases to pull in XML data to populate your site. To start you’ll need a mySQL table which can capture the business information as well as the location. Since Google uses latitude and longitude for precise measurements, these will be floating fields within your database:

CREATE TABLE `locations` (
`id` INT AUTO_INCREMENT PRIMARY KEY ,
`business` VARCHAR( 60 ),
`address` VARCHAR( 80 ),
`latitude` FLOAT( 10, 6 ),
`longitude` FLOAT( 10, 6 ));

With this table you can then import data in CSV format to populate the fields – this is much easier than manual entry.  You can then write SQL statements to find locations in a nearby radius (as defined as its location via longitude and latitude.)  With the mysQL data you can then output the data in XML to deliver information from Google Maps. Most APIs require you to have PHP 5, which has better XML functionality than other coding standards. To improve performance of the open data you’ll want to create an XML node for each unique location (row) in your data – this can help you deliver the results even faster:

<?php

$center_lat = $_GET["latitude"];
$center_lng = $_GET["longitude"];
$radius = $_GET["radius"];
// XML
$dom = new DOMDocument("1.0");
$node = $dom->createElement("locale");
$parent_node = $dom->appendChild($node);

?>

You’ll then need to query the data to output the results in XML, which can then be used to create a list of locations that call the Google Maps API. You can customize this setup to your needs and can explore the API further via Google Code.

0 responses so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment




 

Search Website

 
 
 

Top 10 PHP Hosting Providers

MyHosting - $4.00 USD
InMotion Hosting - $5.95 USD
WebHostingHub - $4.95 USD
JustHost - $3.95 CDN
iPage - $3.50 CDN
HostGator - $4.95 USD
FatCow - $3.67 USD
GreenGeeks - $4.95 USD
BlueHost - $6.95 USD
10 GoDaddy - $4.11 CDN