Map service ComputeDistance method
Calculates the distance between two points in a map (data frame).
ComputeDistance(string MapName, Point FromPoint, Point ToPoint, esriUnits Units)
Parameter |
Description |
---|---|
MapName |
The name of the data frame in the map service. |
FromPoint |
The starting point in the line. The spatial reference is assumed to be the same as the data frame. |
ToPoint |
The ending point in the line. The spatial reference is assumed to be the same as the data frame. |
Units |
The unit of measure in which the distance between two points will be returned. |
Return Value
A double value representing the distance between the FromPoint and ToPoint in the Units defined.
Remarks
The MapName parameter references a data frame name in the map service associated with the map service proxy. The data frame must have a valid spatial reference. The coordinates defined for the both points in the line assume the data frame's spatial reference.
Examples
C#
MapService_MapServer mapservice = new MapService_MapServer();
mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";
string mapname = mapservice.GetDefaultMapName();
wsmap.PointN pnt0 = new PointN();
pnt0.X = -120.0;
pnt0.Y = 30.0;
wsmap.PointN pnt1 = new PointN();
pnt1.X = -110.0;
pnt1.Y = 35.0;
double distance = mapservice.ComputeDistance(mapname, pnt0, pnt1, esriUnits.esriMiles);
VB.NET
Dim mapservice As MapService_MapServer = New MapService_MapServer()
mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer"
Dim mapname As String = mapservice.GetDefaultMapName()
Dim pnt0 As wsmap.PointN = New PointN()
pnt0.X = -120.0
pnt0.Y = 30.0
Dim pnt1 As wsmap.PointN = New PointN()
pnt1.X = -110.0
pnt1.Y = 35.0
Dim distance As Double = mapservice.ComputeDistance(mapname, pnt0, pnt1, esriUnits.esriMiles)
Java
String serviceURL = "http://localhost:6080/arcgis/services/MapService/MapServer";
MapServerBindingStub mapService = new MapServerBindingStub(serviceURL);
String mapName = mapService.getDefaultMapName();
PointN pnt0 = new PointN();
pnt0.setX(-120.0);
pnt0.setY(30.0);
PointN pnt1 = new PointN();
pnt1.setX(-110.0);
pnt1.setY(35.0);
double distance = mapService.computeDistance(mapName, pnt0, pnt1, EsriUnits.esriMiles);
System.out.println("Distance: " + distance);