This example currently accesses the staging environment only. Username, password, and address are required.
In order to run this example, the php_soap extension must be enabled. This was built and tested using PHP 5.3.0.
$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 '
';
echo 'Latitude: '.$lat.' Longitude: '.$lon;
}
?>