Mashups

Derek Bridge

Department of Computer Science,
University College Cork

Mashups

Aims:

Mashups

Mashups

Building a mashup

To build a mashup:

APIs (Application Programming Interface)

Screen scraping

My database-driven mapping mashup

CREATE TABLE markers (
   id INT NOT NULL AUTO_INCREMENT,
   description VARCHAR(100) NOT NULL,
   latitude DOUBLE NOT NULL,
   longitude DOUBLE NOT NULL,
   PRIMARY KEY (id)
);

fetch_markers.php, a PHP script that returns the contents of the database

<?php 
 // Include the PHP to connect to the database
 include('dbconnect.php');
 // Retrieve all markers
 $sql = "SELECT * FROM markers;";
 $dbresult = mysql_query($sql);
 if ( ! $dbresult )
 {
    die('');
 }
 // Output each database row, with commas and vertical bars as separators
 while ($row = mysql_fetch_assoc($dbresult)) 
 {
    echo "{$row['description']},{$row['latitude']},{$row['longitude']}|";
 } 
?>

store_marker.php, a PHP script that stores data in the database

<?php 
 function clean($str)
 {
    return mysql_real_escape_string(trim($str));
 }
 
 // Include the PHP to connect to the database
 include('dbconnect.php');
 // Validate the data again, even though it was done on the client (belt and braces)
 $desc = clean($_GET['desc']);
 $lat = clean($_GET['lat']);
 $lng = clean($_GET['lng']);
 if ( $desc == '' || 
      ! is_numeric($lat) || $lat < -90 || $lat > 90 ||
      ! is_numeric($lng) || $lng < -180 || $lng > 180 )
 {
      die('');
 }
 // Try to insert into the database
 $sql = "INSERT INTO markers (description, latitude, longitude) 
         VALUES ('{$desc}', {$lat}, {$lng});";
 $dbresult = mysql_query($sql);
 if ( ! $dbresult )
 {
      die('');
 }
 // All is well with this new marker
 // Include the cleaned description in the response
 echo $desc;
?>

db_driven_markers.html, the web page that displays the map

This page links to two scripts written in JavaScript:

...
<head>
 <title>Database-driven markers</title>
 <link rel="stylesheet" type="text/css" href="db_driven_markers.css" />
 <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAPuAB5dIIlSZlic4C-yzmcRSY3ZrWNGZjOumIhKGxoGSDJVT-4RRYo5lY6lmmd_gaJoVRlw1NQUc_PQ" type="text/javascript">
 </script>
 <script src="db_driven_markers.js" type="text/javascript">
 </script>
</head>
...the rest is just an HTML form...

db_driven_markers.js, client-side JavaScript that brings it all together

Web services: the future?

Web services: the future?

[Web service providers, consumers and registrars.]

EWeb services diagram from CBDI Web Services Roadmap