Geocoder.ca API
When comes to Canadian geocoding first option you have is geocoder.ca. You can get longitude & latitude, as well as postal codes online from their website, but also, programmatically, using Geocoder.ca API.
You can request values both by HTTP GET or POST using a few combinations: address + city, or free text location or postal code. Result is returned as XML.
Try this:
As you can see, there are only a few parameters: stno, addressst, city & prov if you want to use full address, or locate for free text search, or postal for postal code. There are the same with POST.
To transform this in a web API you only have to include geoit=XML in your requests. The result is an XML file.
See this PHP sample:
$location="1 Yonge St., Toronto, ON";
$req=implode('',file(
'http://geocoder.ca/?geoit=XML&locate='.
urlencode($location)));$p = xml_parser_create();
xml_parse_into_struct($p, $req, $vals);
xml_parser_free($p);if (count($vals)==19) // error occured
{
$er = $vals[2]['value']." - ".
$vals[5]['value'];
$lat = 0;
$long = 0;
} else { // get values
$er = '';
$lat = $vals[1]['value'];
$long = $vals[4]['value'];
}echo "Error:{$er}<br>
Latitude: {$lat}<br>
Longitude: {$long}";
We are getting the results from strict result format, returned as XML file:
<?xml version="1.0″ encoding="UTF-8″ ?>
<geodata>
<latt>43.642321123</latt>
<longt>-79.374806219</longt>
</geodata>
You even don't need to register. There is a limitation per IP address of about 1000 requests per day. For more requests they have commercial licenses.