PHP Classes

File: samples/lineDrive.php

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

Contents

Class file image Download
<?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>Line Drive Map</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="1">
<tr><td>Start Address:</td></tr>
<tr><td>
<textarea name="txtStart" id="txtStart" cols="20" rows="5">1 Microsoft Way Redmond, WA 98052</textarea>
</tr></td>
<tr><td>End Address:</tr></td>
<tr><td>
<textarea name="txtEnd" id="txtEnd" cols="20" rows="5">Pike Place Market Seattle, WA 98101
</textarea>
</tr></td>
<tr><td>Data source: <select name="ddlDataSource" id="ddlDataSource">
    <option selected="selected" value="MapPoint.NA">MapPoint.NA</option>
    <option value="MapPoint.EU">MapPoint.EU</option>
</select>
</tr></td>
<tr><td align="center">
<input type="submit" name="GetLineDriveMap" value="Get Map" id="GetLineDriveMap" />
</tr></td>
</table>
</form>
<?php

if (isset($_POST['GetLineDriveMap'])) {
   
$global = $_SESSION['mappoint'];
   
   
//Find the LatLong for the two addresses provided
   
$aStart = new Address();
   
$aStart->FormattedAddress = $_POST['txtStart'];
   
$aEnd = new Address();
   
$aEnd->FormattedAddress = $_POST['txtEnd'];

   
//we only care about returing the LatLong
   
$fo = new FindOptions();
   
$fo->ResultMask = FindResultMask::$LatLongFlag;

   
//create a new FindAddressSpecification for the start address
   
$spec = new FindAddressSpecification();
   
$spec->DataSourceName = $_POST['ddlDataSource'];
   
$spec->InputAddress = $aStart;
   
$spec->Options = $fo;

   
$fr = null;
   
   
//Get the LatLong for the start address
   
try
    {
       
$fr = $global->FindService->FindAddress($spec);

       
$llStart = new LatLong();
       
$llStart = $fr->Results->FindResult[0]->FoundLocation->LatLong;
    }
    catch (
SoapFault $e) {
        die(
$e->faultstring);
    }
    try
    {
       
//Now get the LatLong for the end address
       
$spec = new FindAddressSpecification();
       
$spec->DataSourceName = $_POST['ddlDataSource'];
       
$spec->InputAddress = $aEnd;
       
$spec->Options = $fo;

       
$fr = $global->FindService->FindAddress($spec);
       
$llEnd = new LatLong();
       
$llEnd = $fr->Results->FindResult[0]->FoundLocation->LatLong;
    }
    catch (
SoapFault $e) {
        die(
$e->faultstring);
    }

   
//use the LatLongs we just obtained to create Location objects
   
$startLocation = new Location();
   
$endLocation = new Location();
   
$startLocation->LatLong = new LatLong();
   
$startLocation->LatLong = $llStart;
   
$endLocation->LatLong = new LatLong();
   
$endLocation->LatLong = $llEnd;

   
//create a SegmentSpecification that includes the
    //start and end locations
   
$routeSegmentsSpec = array();
   
$routeSegmentsSpec[] = new SegmentSpecification();
   
$routeSegmentsSpec[0]->Waypoint = new Waypoint();
   
$routeSegmentsSpec[0]->Waypoint->Name = "Start";
   
$routeSegmentsSpec[0]->Waypoint->Location = $startLocation;
   
$routeSegmentsSpec[] = new SegmentSpecification();
   
$routeSegmentsSpec[1]->Waypoint = new Waypoint();
   
$routeSegmentsSpec[1]->Waypoint->Name = "End";
   
$routeSegmentsSpec[1]->Waypoint->Location = $endLocation;

   
//create a RouteSpecification and add the segments
   
$routeSpec = new RouteSpecification();
   
$routeSpec->DataSourceName = $_POST['ddlDataSource'];
   
$routeSpec->Segments = $routeSegmentsSpec;

   
//Get the LineDrive map(s) and directions
   
try {
       
$myRoute = $global->RouteService->CalculateRoute($routeSpec);
    } catch (
SoapFault $e) {
        die(
$e->faultstring);
    }

   
$format = new ImageFormat();
   
$format->Height = 400;
   
$format->Width = 400;

   
$ldmo = new LineDriveMapOptions();
   
$ldmo->Format = new ImageFormat();
   
$ldmo->Format->Height = 400;
   
$ldmo->Format->Width = 400;
   
$ldmo->FontSize = MapFontSize::$Smallest;
   
$ldmo->ReturnType = MapReturnType::$ReturnUrl;
   
$ldmo->PaletteType = PaletteType::$Color;

   
//now get the maps
   
$spec = new LineDriveMapSpecification();
   
$spec->Route = $myRoute;
   
$spec->Options = $ldmo;
    try {
       
$mi = $global->RenderService->GetLineDriveMap($spec);
    } catch (
SoapFault $e) {
        die(
$e->faultstring);
    }
    echo
"<br /><img src='".$mi[0]->Url."' />";
}

?>
</body>
</HTML>