New MapQuest OpenAPI

MapQuest has just released their OpenAPI for mapping and routing (press release here). Registration and details are at http://www.mapquest.com/features/main.adp?page=developer_tools_oapi 

Of course, we registered and tried them. See their demos hosted here (popup window). To use them, you need an access key obtained after free registration (be careful to register exactly the domain name AND the folder where you want to use them, otherwise you'll get an invalid key error). You need to use this key in all requests from MapQuest.

Here's a simple demo (see it in popup window):

<html>
<head>
<script src="http://web.openapi.mapquest.com/oapi/transaction?request=script&key=mjtd%7Clu6z2l612h%2Cbx%3Do5-d6z2q" mce_src="http://web.openapi.mapquest.com/oapi/transaction?request=script&key=mjtd%7Clu6z2l612h%2Cbx%3Do5-d6z2q"   type="text/javascript"></script>
<title>OpenAPI Sample - Single Map</title>
</head>
<body style="background-color:rgb(244, 246, 229)" id='body' >
<div id='myMap' class='myMap' style="height:400;width:300″>
</div>

<script type="text/javascript">
 var mq = new MQMap("myMap");
 var loc1 = new MQLocation();
 loc1.setName("poi1″);
 loc1.setAddress("1 Yonge Street");
 loc1.setCity("Toronto");
 loc1.setStateProvince("ON");
 loc1.setPostalCode("M5E1W7″);
 loc1.setCountry("CA");
 loc1.setIconId(244);
 mq.locations.add(loc1);
 mq.setRolloverPopups(false);//To disable the popups
 mq.getMap();
</script>
</body>
</html>

Don't forget to change your access key.
Good news is that you can use full addresses, not only geocodes. 

Documentation and support forums are available after registration.

They are available for non-commercial use for 50,000 combined maps and geocodes and 5,000 routes per day. Business solutions are also available.

Comments

Google Maps API

A well-know service, used by many people is Google Maps API. See them at work at maps.google.com.

You can integrate all these maps directly in your websites or applications. Google Maps API is based on JavaScript. You also need to register your ID key used in all map web pages. First thing, is to include Google JavaScript page from http://maps.google.com/maps :

<script src="http://maps.google.com/maps?file=api&v=1&key= … key ID …" type="text/javascript">
 </script>

Then you can use all JavaScript objects and functions provided by this API, documented here. Here's a small example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="content-type" content="text/html; charset=UTF-8″/>

 <title>Google Maps JavaScript API Example: simple</title>
 <script src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAEfCuQGsNiSWxRgf_vfNWaRQjskl1-YgiA_BGX2yRrf7htVrbmBTEB0IH-F489GrwP8-dHLib7cKKIQ" mce_src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAEfCuQGsNiSWxRgf_vfNWaRQjskl1-YgiA_BGX2yRrf7htVrbmBTEB0IH-F489GrwP8-dHLib7cKKIQ"
   type="text/javascript">
 </script>

 <script type="text/javascript">
 function onLoad() {
   if (GBrowserIsCompatible()) {
   var map = new GMap(document.getElementById("map"));
   map.centerAndZoom(new GPoint(-122.1419, 37.4419), 4);
   }
 }
</script>
</head>
<body onload="onLoad()">
<div id="map" style="width: 500px; height: 300px"></div>
</body>
</html> 

Idea is simple: create an GMap object based on a GPoint object created from longitude and latitude. Then you can add more objects as layers (GMarker) with their own events (GEvent).

Let's see a little bit more complicated demo with more functionality (popup window). This sample will work only from our website because of the ID key (unless you change it). As you can see, after loading, the maps are independent from your webpage, with their own navigation. All points must be specified by their longitude and latitude, you can't use full addresses. To get this geocodes you can use other websites like www.infosports.com/m/map.htm or www.geocoder.us.

Google API offers much more functionality. You can add markers to the map, with their own events and HTML content. Let's see such an example, with a marker and custom text displayed when click it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <script src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAMWlN5S_pnUghkzaCL6OMMhRPit09n3FXh9HBeHPLQkDYD-WLrxTsecUOe9Urm4gtthzKpsI0hcmToA" mce_src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAMWlN5S_pnUghkzaCL6OMMhRPit09n3FXh9HBeHPLQkDYD-WLrxTsecUOe9Urm4gtthzKpsI0hcmToA" type="text/javascript"></script>
  </head>
  <body>
    <div id="map" style="width: 400px; height: 300px"></div>
    <script type="text/javascript">
   
    var map = new GMap(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    var point = new GPoint(-79.3763, 43.6458);
    map.centerAndZoom(point, 8 );
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml("Hi there!");
    });
    map.addOverlay(marker);
    </script>
  </body>
</html> 

For a full description of the objects, their methods, events and properties see their documentation (including more complex samples).

Comments

Yahoo Spell Checker API

Another web service available from Yahoo is online spell checker. Thsi service is similar with Yahoo web search: you provide all parameters with REST and get results as XML, JSON or serialized PHP. URL used for this service is http://api.search.yahoo.com/WebSearchService/V1/spellingSuggestion and its description with all parameters is at http://developer.yahoo.net/search/web/V1/spellingSuggestion.html.

Here's an example from JavaScript using JSON:

<script language=JavaScript>
function ws_results(obj) {
alert("Correct spelling of 'someting' is '"+obj.ResultSet.Result+"'");
}
</script>
<script type="text/javascript"
src="http://api.search.yahoo.com/WebSearchService/V1/spellingSuggestion?appid=YahooDemo&query=someting&output=json&callback=ws_results">
</script>

And something similar with serialized PHP:

$request =  'http://api.search.yahoo.com/WebSearchService/V1/spellingSuggestion?appid=YahooDemo&query=someting&output=php';

$response = implode('',file($request));

if ($response === false) {
 die('Request failed');
}

$phpobj = unserialize($response);

echo "Correct spelling of 'someting' is '{$phpobj['ResultSet']['Result']}'"; 

Simply, isn't it? There is the same 5000 queries limit per day per IP for this web service.

Comments

Yahoo Search API

Yahoo searches are a little bit more complex (or simplier?) because there are more options for getting the results and where searches are performed. For this reason we separated them from spell checker, also available from Yahoo.

To perform Yahoo searches you'd need to register an application ID and then pass proper parameters thru REST to search pages located at http://api.search.yahoo.com/WebSearchService/V1/webSearch.

You can found all input & output parameters at http://developer.yahoo.net/search/web/V1/webSearch.html . Basicaly, Yahoo accepts parameters in a single way (REST) and return results in 3 possible ways, at your choice: XML (default), JSON & serialized PHP (based on serialize / unserialize functions from PHP, available since PHP 3.05). Depending on your needs, one or another solution to get results may be more convenient.

You can download from Yahoo website examples for Macromedia Flash, Java, JavaScript, PHP & Python. Server-side, especially in PHP the simplest method is using serialized results (available not only from PHP but other languages too, see this page, like C#, Python, Ruby and more). Here's an example with PHP:

$request =  'http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=something&results=10&output=php';

$response = implode('',file($request));

if ($response === false) {
 die('Request failed');
}

$phpobj = unserialize($response);

foreach($phpobj['ResultSet']['Result'] as $arr) {
  echo "<p><a href='{$arr['Url']}' target='_blank'>{$arr['Title']}</a>\n
           <br>{$arr['Summary']}</p>\n";

Don't forget to replace your application ID and your custom parameters.

JSON version is useful, especially from JavaScript, client-side:

<script language=JavaScript>
function ws_results(obj) {
  var res=obj.ResultSet.Result;
  for (var i = 0;i     document.write("<p><a href='"+res[i].Url+"' target='_blank'>"+
    res[i].Title+"</a>\n<br>"+
    res[i].Summary+"</a></p>\n");
}
</script>

<script type="text/javascript"
src="http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=something&results=10&output=json&callback=ws_results" mce_src="http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=something&results=10&output=json&callback=ws_results">
</script>

It's very important to declare ws_results() callback function before calling Yahoo service. It automatically create an object parameter (obj) based on raw result returned by Yahoo service.

XML examples are provided by Yahoo, so I don't insist on them now.

Yahoo services have a limit of 5000 queries per day per IP. When you hit this limit an error message is returned. You have a log of these searches at http://api.search.yahoo.com/webservices/usage_data

As you can see, there is not very hard to integrare Yahoo search with your websites or applications. For other Yahoo services check our website.

Comments

Google Search and Spell Checker

Let's start our web API discussion with a first example: Google Search and Spell Checker.

First step is to register a free account. You'll get a key required when using Google functions.

Here's an example how to use it with NuSOAP and PHP:

# Use the NuSOAP php library (provide relative path to include file)
require_once('nusoap.php');

# Set parameters
$parameters = array(
    'key'=>'… your key from Google …',
    'q' => 'keywords for search',
    'start' => 0,
    'maxResults' => '10′,
    'filter' => 'false',
    'restrict' => '',
    'safeSearch' => 'false',
    'lr' => '',
    'ie' => 'latin',
    'oe' => 'latin'
  );

$soapclient =
  new soapclient('http://api.google.com/GoogleSearch.wsdl', 'wsdl');

$results = $soapclient->call('doGoogleSearch',$parameters);

if ( is_array($results['resultElements']) ) {
   echo "<p>Your Google query found "
  . $results['estimatedTotalResultsCount'] . ":</p>";

  foreach ( $results['resultElements'] as $result ) {
    echo "<p><a href='" . $result['URL'] .
      "' target='_blank'>" .
     ( $result['title'] ? $result['title'] : 'no title' ) .
     "</a><br>" . $result['URL'] . "<br>" .
     ( $result['snippet'] ? $result['snippet'] : 'no snippet' ) .
     "<br>".$result['URL']."</p>";
     }
}

This code creates a SOAP client with entry point http://api.google.com/GoogleSearch.wsdl, then call doGoogleSearch() function with imitialized parameters ($parameters). These parameters are straightforward, with the key provided after Google account registration, your keyword keys, start page and the number of results, as well as other parameters.

At the end, you can display results from $results array in any form you want, maybe integrated with other content.

Another useful Google service is online spell checking, available in a similar manner:

# Use the NuSOAP php library
require_once('nusoap.php');

# Set parameters
$parameters = array(
    'key'=>' … your key from Google …',
    'phrase' => 'someting wroong',
    'start' => 0,
    'maxResults' => '10′,
    'filter' => 'false',
    'restrict' => '',
    'safeSearch' => 'false',
    'lr' => '',
    'ie' => 'latin',
    'oe' => 'latin'
  );

$soapclient =
   new soapclient('http://api.google.com/GoogleSearch.wsdl', 'wsdl');

$results = $soapclient->call('doSpellingSuggestion',$parameters);
echo($results);

Notice parameter difference for each service: for searching is used 'q' parameter and for spell checker 'phrase'. Spell-checker phrase is limited to 1024 characters and 10 words.

Google search and spell-checker is limited to 1,000 searches per day. There are no commercial accounts at this time, for more searches. For other details see Google FAQ or API Reference (with parameters description). Also, you can download from Google examples for Java and .NET.

Or see this sample at work (in a popup window).

Other links:

Comments

Welcome to WebAPI.org

Welcome to WebAPI.org

First of all, what's WebAPI.org? It's a free website focused on Internet services available online from different providers, using different technologies and methods. This is a directory of such APIs, with script samples, links and reviews.

More and more companies offer web APIs for useful purposes, in order to expand their client base and enhance other developer applications. For them, it's just another method to bring new visitors or keep satisfied their clients. For users, is a good source of online service, many times for free. For developers, is a challenge to keep their applications up to date with latest technologies and more functionality.

There is not an easy definition of what Web APIs are, and even there are no standards for many solutions or W3C recommendations for them, but we still must know what they are and how to benefit using them. It's like integrating solutions from multiple companies in a dynamic and useful product. Results could be spectacular and can ease our work.

We'll try to offer here details on what a web API offers, how to use it, samples and links.

Web APIs are a very hot and dynamic topic, so, almost every week there are new solutions. We'll try to keep up to date as possible, but still there is no promise. Thanks for helping us with information, correction or comments.

Comments

Next entries » ·