Select to view content in your preferred language

Distance between 2 Points

989
6
10-12-2010 06:25 AM
TonyCollins
Regular Contributor
Quite simply, if I have two MapPoints how would I measure the distance between them?

I tried to create a polyline using these points and then call the lengths method on geometry service but the results array is allways empty.
Tags (2)
0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus
0 Kudos
TonyCollins
Regular Contributor
Tony,

   Look at this sample.

http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=MeasureDistance


Hi Robert, thanks for the link.

I looked up distance on the API as I figured it would be a common task, but decided I could not use it due to reference to server 10 (very depressing as I have 9.3.1)

distance(distanceParameters:DistanceParameters, responder:IResponder = null):AsyncToken
The distance operation is performed on a geometry service resource (only available with ArcGIS Server 10.0 or above).


This is why I have been trying with a polyline...
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Tony,

    What does your code for building the polyline look like?
0 Kudos
TonyCollins
Regular Contributor
Tony,

    What does your code for building the polyline look like?


Thanks for your help Robert!

I have tried creating the polyline many ways and most seem to create one, but here is what I currently have:

var schoolMapPoint:MapPoint = findResult.feature.geometry as MapPoint; 
var addressMapPoint:MapPoint = parentApplication.addressMapPoint;
var mapPoints:Array = [schoolMapPoint,addressMapPoint];
var polyLine:Polyline = new Polyline([mapPoints]);
..
..
lengthsParameters.polylines = [polyLine];
geometryService.lengths(lengthsParameters);
0 Kudos
TonyCollins
Regular Contributor
Hmm... hold up it now looks like I have a result...
Will post back after a little more debugging!
0 Kudos
TonyCollins
Regular Contributor
Firstly sorry to have wasted your time Robert, but at least this might help someone on 9.3.1 if there are any left!

It looks like my issue was that I was not giving the polyLine a spatialReference (although I'm sure I already tried that).

NOTE: I'm not using any map
0 Kudos