C
View more presentations from siranen.
Spowiedz jest w trakcie pisania - jeżeli kogo nie przerazi ok 10 str A4 - bo jak tłumaczyć się na postawione mi zarzuty - to konkretnie.
private void btnDirections_Click(object sender, EventArgs e)
{
txtResults.Text = string.Empty;
stsMain.Text = string.Empty;
FindSpecification findSpec = new FindSpecification();
FindResults startResults = null;
FindResults endResults = null;
findSpec.DataSourceName = cmbZone.Text;
findSpec.InputPlace = txtOrigAddress.Text;
try
{
startResults = findService.Find(findSpec);
}
catch
{
MessageBox.Show("Problem connecting with service");
}
findSpec.InputPlace = txtDestAddress.Text;
try
{
endResults = findService.Find(findSpec);
}
catch
{
MessageBox.Show("Problem connecting with service");
}
if(startResults == null)
{
MessageBox.Show("Originating Address not found.");
}
else
{
if(startResults.NumberFound == 0)
{
MessageBox.Show("Originating Address not found.");
return;
}
}
if(endResults == null)
{
MessageBox.Show("Destination Address not found.");
}
else
{
if(endResults.NumberFound == 0)
{
MessageBox.Show("Destination Address not found.");
return;
}
}
stsMain.Text = "Generating Route Information";
GetRoute(startResults,endResults);
}
+
private void GetRoute(FindResults sResults,
FindResults eResults)
{
SegmentSpecification[] routeSegment;
routeSegment = new SegmentSpecification[2];
routeSegment[0]= new SegmentSpecification();
routeSegment[0].Waypoint = new Waypoint();
routeSegment[0].Waypoint.Name =
sResults.Results[0].FoundLocation.Entity.Name;
routeSegment[0].Waypoint.Location =
sResults.Results[0].FoundLocation;
routeSegment[1]= new SegmentSpecification();
routeSegment[1].Waypoint = new Waypoint();
routeSegment[1].Waypoint.Name =
eResults.Results[0].FoundLocation.Entity.Name;
routeSegment[1].Waypoint.Location =
eResults.Results[0].FoundLocation;
RouteSpecification routeSpecs =
new RouteSpecification();
routeSpecs.DataSourceName = cmbZone.Text;
routeSpecs.Segments = routeSegment;
RouteServiceSoap routeService = new RouteServiceSoap();
routeService.Credentials = myCredentials;
routeService.PreAuthenticate = true;
Route route = new Route();
route = routeService.CalculateRoute(routeSpecs);
stsMain.Text = "Fetching Route Information";
for (int i = 0;
i < class="code-digit">0].Directions.Length;i++)
{
txtResults.Text +="("+(i+1)+") "+
route.Itinerary.Segments[0].Directions[i].Instruction +
" >> ";
}
stsMain.Text = "Wait...Generating Map Information";
MapSpecification mapSpec = new MapSpecification();
mapSpec.Options = new MapOptions();
mapSpec.Options.Format = new ImageFormat();
mapSpec.Options.Format.Height = pcMap.Height;
mapSpec.Options.Format.Width = pcMap.Width;
mapSpec.DataSourceName = cmbZone.Text;
mapSpec.Route = route;
try
{
// Get the map image
MapImage tempImage =
renderService.GetMap(mapSpec)[0];
pcMap.Image = new Bitmap(
new MemoryStream(tempImage.MimeData.Bits,
false), true);
stsMain.Text = "Done";
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
}
Trochę lepiej ale dalej klaps - nie ma tutaj wyjątku na mapy polskie - stąd integracja z GIS'em
Ale to już w następnym wpisie
P.S.
Session has not been terminated