<?php
require_once('../mappoint/ClassLoader.php');
session_start();
if (!isset($_SESSION['addresses'])) {
$_SESSION['addresses'] = array();
}
if (isset($_POST['findAddress'])) {
/*This code is a translation of the FindAddress sample of the Mappoint Documention.
I'd recommend you to check the sample and compare it with this one.*/
$global = $_SESSION['mappoint'];
$myAddress = new Address();
$myAddress->FormattedAddress = $_POST['textAddressString'];
$myFindOptions = new FindOptions();
$myFindOptions->ThresholdScore = 0;
$findAddressSpec = new FindAddressSpecification();
$findAddressSpec->InputAddress = $myAddress;
$findAddressSpec->Options = $myFindOptions;
$findAddressSpec->DataSourceName = $_POST['dataSource'];
try {
$myFindResults = $global->FindService->FindAddress($findAddressSpec);
} catch (SoapFault $e) {
die($e->faultstring);
}
$_SESSION['addresses'] = array();
if ($myFindResults->Results == null) {
$_SESSION['addresses'][] = array(0, "No results found.");
} else {
for ($i = 0; $i < $myFindResults->NumberFound; $i++) {
$_SESSION['addresses'][] = array(
$myFindResults->Results->FindResult[$i]->FoundLocation->LatLong->Latitude
."/".$myFindResults->Results->FindResult[$i]->FoundLocation->LatLong->Longitude,
$myFindResults->Results->FindResult[$i]->FoundLocation->Entity->DisplayName);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Find Address</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="1">
<tr>
<td colspan="2" style="text-align:center; font-weight:bold">Find Address</td>
</tr>
<tr>
<td>DataSource: </td>
<td>
<select name="dataSource" id="dataSource">
<option value="MapPoint.EU">MapPoint.EU</option>
<option value="MapPoint.NA">MapPoint.NA</option>
<option value="MapPoint.BR">MapPoint.BR</option>
</select>
</td>
</tr>
<tr>
<td>Address: </td>
<td><input type="text" name="textAddressString" id="textAddressString" value="1 Main St., Bogus City" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" name="findAddress" value="Find Address" />
</td>
</tr>
<tr>
<td colspan="2">Select the address you are looking for:</td>
</tr>
<tr>
<td colspan="2">
<select name="address" id="address" multiple="multiple" size="5" style="width:100%" onchange="window.open('<?php echo $_SERVER['PHP_SELF'];?>?location=' + this.value + '&dataSource=' + document.getElementById('dataSource').value, '_self')">
<?php
foreach ($_SESSION['addresses'] as $address) {
echo "<option value='".$address[0]."'>".$address[1]."</option>";
}
?>
</select>
</td>
</tr>
</table>
<?php
if (isset($_GET['location'])) {
if ($_GET['location'] != 0) {
/*This code is a translation of the RenderMap method implemented in the FindAddress sample.*/
$global = $_SESSION['mappoint'];
$latLongs = split('/', $_GET['location']);
$myMapView = new ViewByScale();
$myMapView->CenterPoint = new LatLong();
$myMapView->CenterPoint->Latitude = $latLongs[0];
$myMapView->CenterPoint->Longitude = $latLongs[1];
$myMapView->MapScale = 50000;
$myMapOptions = new MapOptions();
$myMapOptions->ReturnType = MapReturnType::$ReturnUrl;
$myMapOptions->Format = new ImageFormat();
$myMapOptions->Format->Height = 500;
$myMapOptions->Format->Width = 500;
$myPushPin = new Pushpin();
$myPushPin->PinID = "pin0";
$myPushPin->Label = "CenterPoint";
$myPushPin->IconName = "0";
$myPushPin->IconDataSource = "MapPoint.Icons";
$myPushPin->LatLong = $myMapView->CenterPoint;
$mapSpec = new MapSpecification();
$mapSpec->Options = $myMapOptions;
$mapSpec->Views = array($myMapView);
$mapSpec->Pushpins = array($myPushPin);
$mapSpec->DataSourceName = $_GET['dataSource'];
$mapImage = null;
try {
$mapImage = $global->RenderService->GetMap($mapSpec);
} catch (SoapFault $e) {
die($e->faultstring);
}
echo "<img src='".$mapImage[0]->Url."' />";
}
}
?>
</form>
</body>
</html>
|