PHP Classes

File: samples/findNearby.php

Recommend this page to a friend!
  Classes of Carlos Machado  >  MapPoint PHP API  >  samples/findNearby.php  >  Download  
File: samples/findNearby.php
Role: Example script
Content type: text/plain
Description: FindNearby test
Class: MapPoint PHP API
Access MapPoint Web services
Author: By
Last change:
Date: 11 years ago
Size: 7,179 bytes


Class file image Download

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sample Find Nearby Fourth Coffee</title>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="1">
    <td colspan="2"><b>Sample Find Nearby Fourth Coffee</b></td>
    <td>Data source:</td>
    <select name="listDataSource" id="listDataSource">
        <option selected="selected" value="MapPoint.NA">MapPoint.NA</option>
        <option value="MapPoint.EU">MapPoint.EU</option>
    <td>Street address: </td>
    <td><input name="textAddressLine" type="text" value="1 Microsoft Way" id="textAddressLine" /></td>
    <td><input name="textPrimaryCity" type="text" value="Redmond" id="textPrimaryCity" /></td>
    <td>Secondary city:</td>
    <td><input name="textSecondaryCity" type="text" id="textSecondaryCity" /></td>
    <td><input name="textSubdivision" type="text" value="WA" id="textSubdivision" /></td>
    <td>Postal code:</td>
    <td><input name="textPostalCode" type="text" value="98052" id="textPostalCode" /></td>
    <td>Country or region:</td>
    <select name="listCountryRegion" id="listCountryRegion">
        <option selected="selected" value="USA">USA</option>
        <option value="Canada">Canada</option>
    <td>Search radius: </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>
    <td align="center" colspan="2">
    <input type="submit" name="buttonFindNearby" value="Find" id="buttonFindNearby" />

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."'>";
$myFindNearbyResults->Results->FindResult[$i]->FoundLocation->Entity->DisplayName ."</option>";
// 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);
"<br /><img src='".$myMapImages[0]->Url."' />";
    } catch (
SoapFault $e) {