<?php
require_once('../mappoint/ClassLoader.php');
session_start();
?>
<!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>Sample Find Nearby Fourth Coffee</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="1">
<tr>
<td colspan="2"><b>Sample Find Nearby Fourth Coffee</b></td>
</tr>
<tr>
<td>Data source:</td>
<td>
<select name="listDataSource" id="listDataSource">
<option selected="selected" value="MapPoint.NA">MapPoint.NA</option>
<option value="MapPoint.EU">MapPoint.EU</option>
</select>
</td>
</tr>
<tr>
<td>Street address: </td>
<td><input name="textAddressLine" type="text" value="1 Microsoft Way" id="textAddressLine" /></td>
</tr>
<tr>
<td>City:</td>
<td><input name="textPrimaryCity" type="text" value="Redmond" id="textPrimaryCity" /></td>
</tr>
<tr>
<td>Secondary city:</td>
<td><input name="textSecondaryCity" type="text" id="textSecondaryCity" /></td>
</tr>
<tr>
<td>Subdivision:</td>
<td><input name="textSubdivision" type="text" value="WA" id="textSubdivision" /></td>
</tr>
<tr>
<td>Postal code:</td>
<td><input name="textPostalCode" type="text" value="98052" id="textPostalCode" /></td>
</tr>
<tr>
<td>Country or region:</td>
<td>
<select name="listCountryRegion" id="listCountryRegion">
<option selected="selected" value="USA">USA</option>
<option value="Canada">Canada</option>
</select>
</td>
</tr>
<tr>
<td>Search radius: </td>
<td>
<select name="listRadius" id="listRadius">
<option value="1">1</option>
<option value="2">2</option>
<option selected="selected" value="5">5</option>
<option value="10">10</option>
</select>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" name="buttonFindNearby" value="Find" id="buttonFindNearby" />
</td>
</tr>
</table>
</form>
<?php
if (isset($_POST['buttonFindNearby'])) {
$global = $_SESSION['mappoint'];
//Create and populate an Address object for the FindAddress request
$myAddress = new Address();
$myAddress->AddressLine = $_POST['textAddressLine'];
$myAddress->PrimaryCity = $_POST['textPrimaryCity'];
$myAddress->SecondaryCity = $_POST['textSecondaryCity'];
$myAddress->Subdivision = $_POST['textSubdivision'];
$myAddress->PostalCode = $_POST['textPostalCode'];
$myAddress->CountryRegion = $_POST['listCountryRegion'];
//Set up the Find options
$myFindOptions = new FindOptions();
$myFindOptions->ThresholdScore = 0;
// Set up the specification object
$findAddressSpec = new FindAddressSpecification();
$findAddressSpec->Options = $myFindOptions;
$findAddressSpec->DataSourceName = $_POST['listDataSource'];
$findAddressSpec->InputAddress = $myAddress;
// Declare a FindResults object to hold the FindAddress results
$myFindResults = null;
try {
$myFindResults = $global->FindService->FindAddress($findAddressSpec);
if ($myFindResults->NumberFound == 0) {
//If there are no results from the address find, then just tell the user
die("No addresses matches found.");
}
else {
//Set up the FindNearby options object
$myFindNearbyOptions = new FindOptions();
$myFindNearbyOptions->Range = new FindRange();
$myFindNearbyOptions->Range->Count = 25;
//Set up the specification object
$findNearbySpec = new FindNearbySpecification();
$findNearbySpec->Options = $myFindNearbyOptions;
$findNearbySpec->DataSourceName = "MapPoint.FourthCoffeeSample";
$findNearbySpec->Distance = $_POST['listRadius'];
$findNearbySpec->LatLong = $myFindResults->Results->FindResult[0]->FoundLocation->LatLong;
$findNearbySpec->Filter = new FindFilter();
$findNearbySpec->Filter->EntityTypeName = "FourthCoffeeShops";
$findNearbySpec->Filter->PropertyNames = array("DisplayName");
//Create a FindResults object to store the results of the FindNearby request
$myFindNearbyResults = null;
$myFindNearbyResults = $global->FindService->FindNearby($findNearbySpec);
//Now use the found address and the FindNearby results to render a map.
//Output the results of the FindNearby search as well.
//Create an array of Location and Pushpin objects, setting upperbound via the upperbound of the FindNearby results,
//adding one array element for the original address. Draw the map to encompass all these points.
$myLocations = array();
$myPushPins = array();
//Add FindNearby results to the list box and fill the pushpin and location arrays
echo "<select name='findNearbyResults' id='findNearbyResults' size='5' multiple='multiple'>";
$i = 0;
for ($i = 0; $i < $myFindNearbyResults->NumberFound - 1; $i++) {
$myLocations[$i] = new Location();
$myLocations[$i]->LatLong = $myFindNearbyResults->Results->FindResult[$i]->FoundLocation->LatLong;
$myPushPins[$i] = new Pushpin();
$myPushPins[$i]->PinID = "pin" + $i;
$myPushPins[$i]->IconName = "CoffeeShopIcon";
$myPushPins[$i]->IconDataSource = "MapPoint.Icons";
$myPushPins[$i]->LatLong = $myFindNearbyResults->Results->FindResult[$i]->FoundLocation->LatLong;
//Add the name and lat/long values to the find nearby results list
echo "<option value'".$myFindNearbyResults->Results->FindResult[$i]->FoundLocation->Entity->Properties->Property[0]->Value." - lat: "
. $myLocations[$i]->LatLong->Latitude . " - lon: " . $myLocations[$i]->LatLong->Longitude."'>";
echo $myFindNearbyResults->Results->FindResult[$i]->FoundLocation->Entity->DisplayName ."</option>";
}
echo "</select>";
// We repeat the entire myLocations/myPushPins action one more time to get a pin in for the original address.
$myLocations[$i] = $myFindResults->Results->FindResult[0]->FoundLocation;
$myPushPins[$i] = new Pushpin();
$myPushPins[$i]->PinID = "pin" + $i;
$myPushPins[$i]->Label = $_POST['textAddressLine'];
$myPushPins[$i]->IconName = "0";
$myPushPins[$i]->IconDataSource = "MapPoint.Icons";
$myPushPins[$i]->LatLong = $myFindResults->Results->FindResult[0]->FoundLocation->LatLong;
//Set up the specification object using the location array
$myViews = array();
$myViews[] = new ViewByBoundingLocations();
$myViews[0]->Locations = $myLocations;
$mapSpec = new MapSpecification();
$mapSpec->Pushpins = $myPushPins;
$mapSpec->Views = $myViews;
$mapSpec->DataSourceName = $_POST['listDataSource'];
$mapSpec->Options = new MapOptions();
$mapSpec->Options->ReturnType = MapReturnType::$ReturnUrl;
$mapSpec->Options->Format = new ImageFormat();
$mapSpec->Options->Format->Width = 500;
$mapSpec->Options->Format->Height = 500;
//get the map
$myMapImages = null;
$myMapImages = $global->RenderService->GetMap($mapSpec);
echo "<br /><img src='".$myMapImages[0]->Url."' />";
}
} catch (SoapFault $e) {
die($e->faultstring);
}
}
?>
</body>
</html>
|