Geo!Suggest


Geo!Suggest = Yahoo Geocoding API + AJAX

Source Code::./service.yahoo.geocode.php


[LineNum : OFF]  [Download]

1 <?php
2
/** 
3 * Geo!Suggest
4
5 * @package Geo!Suggest
6 * @version 1.0
7
8 * This is a server side script of Geo!Suggest tool.
9 * The main responsibility for this script is communication with Yahoo Geocodingg API and sending
10 * results back to the client application (Geo!Suggest) 
11
12 * History 
13 * 11/12/2005 A. Bidochko 
14 * - Created. 
15 */
16
17 // Get input parameter
18
$sAddress = (isset($_GET['address']) ? $_GET['address'] : '');
19
20
// We will send xml file back to the server
21
Header("Content-type: text/xml; charset=UTF-8");
22
23
//do we have an address?
24
if (empty($sAddress))
25 {
26     
// Return error
27     
$sResponse "<Error>The following errors were detected:<Message>Location is empty</Message></Error>";
28     
// Output the result XML
29     
echo $sResponse;
30     
// Succesfully terminate this script
31     
exit(0);
32 }
33
34
################################################################################
35 # Talk to Yahoo Geocoding Service
36 ################################################################################
37
38 // Set misc values needed for the curl command
39
$sPathToCurl        'curl' ;
40
$sPostToURL         'http://api.local.yahoo.com/MapsService/V1/geocode' ;
41
$aPostData          = array() ;  // This will hold the fieldname/value pairs
42
$sEncapChar         '"';
43
$aData['appid']     = 'mapbuilder.net';
44
45
//Create fieldname/value pairs
46
foreach($aData as $sVar => $sValue)
47 {
48     
// Double quotes are removed from the data and replaced with '*'.
49     // except for the encapsulation character
50     
$sValue str_replace($sEncapChar'*'$sValue);
51
52     
//URLencode the key and value and make them a name/value pair
53     
$aPostData[] = urlencode($sVar) . '=' urlencode($sValue);
54 }
55
56
//Seperate by & each of the name/value pairs
57
$sPostData implode('&'$aPostData);
58
59
//Append Location
60
$sPostData .= '&location=' rawurlencode($sAddress);
61
62
//Execute curl command
63
$sPostString $sPathToCurl ' -s  --get --data ' escapeshellarg($sPostData) . ' ' escapeshellarg($sPostToURL);
64
$sResponse shell_exec($sPostString);
65
// Output the result XML
66
echo $sResponse;
67
68
?>