Analysis
Data Reviewer
Directions and Routing
Dynamic Layers
Editing
Feature Layers
Feature Table
Graphics
Image Layers
Map
Mobile
Online and Portal
Popups and Info Windows
Printing
Query and Select
Renderers, Symbols, Visualization
Search
Tiled Layers
Time
Measure distances

#### Description

This example shows how you can use an ArcGIS Server geometry service to measure line lengths in your Web application. When you click and drag the mouse, the Draw toolbar captures the geometry of the line you drew. It sends the line to the geometry service, which calculates the length of the line using the GeometryService.lengths() method.

#### Code

```<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Measure Distances</title>

<script src="https://js.arcgis.com/3.41/"></script>
<script>
dojo.require("esri.map");
dojo.require("esri.toolbars.draw");
dojo.require("dojo.number");

var map, geometryService;

function init() {
map = new esri.Map("map", {
basemap: "streets-vector",
center: [-77.500, 42.500],
zoom: 7
});
dojo.connect(geometryService, "onLengthsComplete", outputDistance);
}

function initFunctionality(map) {
var tb = new esri.toolbars.Draw(map);
//on draw end add graphic, project it, and get new length
dojo.connect(tb, "onDrawEnd", function(geometry) {
map.graphics.clear();

lengthParams.polylines = [geometry];
lengthParams.geodesic = true;

geometryService.lengths(lengthParams);
var graphic = map.graphics.add(new esri.Graphic(geometry, new esri.symbol.SimpleLineSymbol()));
});
tb.activate(esri.toolbars.Draw.FREEHAND_POLYLINE);
}

function outputDistance(result) {
dojo.byId("distance").innerHTML = dojo.number.format(result.lengths[0] / 1000) + " kilometers";
}