backoffice/includes/partenaires/classMMapi_bing.php
2011-06-21 13:28:10 +00:00

113 lines
3.7 KiB
PHP

<html>
<head>
<title>Imagery Service example in PHP (with Geocode)</title>
</head>
<body>
This example currently accesses the staging environment only. Username, password, and address are required.<br>
In order to run this example, the php_soap extension must be enabled. This was built and tested using PHP 5.3.0.<br><br>
<form action="imageryservicesample.php" method="post">
Username: <input type="text" name="username" value="<?php echo (isset($_POST['username'])?$_POST['username']:'') ?>">
Password: <input type="text" name="password" value="<?php echo (isset($_POST['password'])?$_POST['password']:'') ?>"><br>
Address: <input type="text" name="address" value="<?php echo (isset($_POST['address'])?$_POST['address']:'') ?>"><br>
Zoom: <input type="text" name="zoomlevel" value="<?php echo (isset($_POST['zoomlevel'])?$_POST['zoomlevel']:'') ?>"><br>
<input type="submit" value="Submit">
</form>
<?php
if(isset($_POST['username']) && isset($_POST['password']))
{
$UserName = $_POST['username'];
$Password = $_POST['password'];
// Url to the token service wsdl (for now it's a local file)
$TokenServiceWsdl = "tokenreference.wsdl";
// Create the service client object
//trace allows us to see last response and request for debugging
$tokenClient = new SoapClient($TokenServiceWsdl, array('login' => $UserName, 'password' => $Password, 'trace' => true));
// TokenSpecification "object"
$tokenSpec = array(
'ClientIPAddress' => '0.0.0.0',
'TokenValidityDurationMinutes' => '60'
);
try {
// Get the client token
$tokenResponse = $tokenClient->GetClientToken(array('specification' => $tokenSpec));
}
catch(SoapFault $e)
{
die('Fault occurred using Web Service: '.$e->getMessage());//.print_r($res,true));
}
// Get the token from the response object
$token = $tokenResponse->GetClientTokenResult;
// URLs to the Imagery and Geocode services
$imageryServiceWsdl = 'imageryservice.wsdl';
$geocodeServiceWsdl = 'geocodeservice.wsdl';
// Credentials "object"
$credentials = array('Token' => $token);
// Create the geocode service and imagery service clients
$geocodeClient = new SoapClient($geocodeServiceWsdl, array('trace' => 1));
$imageryClient = new SoapClient($imageryServiceWsdl, array('trace' => 1));
// GeocodeRequest "object"
$geocodeRequest = array(
'Credentials' => $credentials,
'Query' => $_POST['address']
);
try {
if(isset($_POST['address']))
$geocodeResponse = $geocodeClient->Geocode(array('request' => $geocodeRequest));
}
catch(SoapFault $e)
{
die('Fault occurred using Web Service: '.$e->getMessage());
}
// Retrieve the latitude and longitude from the response object
$lat = $geocodeResponse->GeocodeResult->Results->GeocodeResult->Locations->GeocodeLocation->Latitude;
$lon = $geocodeResponse->GeocodeResult->Results->GeocodeResult->Locations->GeocodeLocation->Longitude;
// Location "object"
$location = array(
'Latitude' => $lat,
'Longitude' => $lon
);
if($_POST['zoomlevel'] == '')
$_POST['zoomlevel'] = null;
// MapUriOptions "object"
$options = array(
'ZoomLevel' => $_POST['zoomlevel']
);
// MapUriRequest "object"
$mapUriRequest = array(
'Credentials' => $credentials,
'Center' => $location,
'Options' => $options
);
try {
// GetMapUri method call
$mapUriResponse = $imageryClient->GetMapUri(array('request' => $mapUriRequest));
}
catch(SoapFault $e)
{
die('Fault occurred using Web Service: '.$e->getMessage());
}
// Display the URI and lat/lon returned from the service call
echo '<img src="' . $mapUriResponse->GetMapUriResult->Uri . '"><br>';
echo 'Latitude: '.$lat.' Longitude: '.$lon;
}
?>
</body>
</html>