Make measurements

Just as there are many types of projections available to display the earth's surface on a two-dimensional map, there are a variety of methods for measuring distance or area. As when choosing a projection, you need to understand the characteristics of measurement methods when making measurements for a particular use.

The following are some questions to ask when working with geographic measurements:

  • Will measurements be at a large or small scale? The curvature of the earth's surface is not as much of a factor for measurements made at a larger scale (smaller areas).

  • What coordinate system will be used? With a projected coordinate system, the properties of the underlying projection greatly influence the accuracy of measurements in a given area of the map.

  • How accurate do measurements need to be? Sometimes you want to interactively explore using approximate measurements. At other times, a high level of accuracy is required.

  • Will measurements include things above or below the surface of the earth? Some measurement methods do not consider the z-value (elevation or altitude) for the geometry being measured.

  • Should measurements take topography into account? Distance for a hiking trail, for example, is more accurate if it accounts for travel across the surface terrain.

  • Are measurements being made for travel on a predefined line network (representing roads or trails, for example). See Route and directions to see how to model this kind of travel and make measurements in distance and time or other costs.

Planar versus geodetic measurements

Planar measurements are made with straight lines in two dimensions. If you're using a geographic coordinate system, planar measurements must cut through the curved surface of the earth rather than following it (similar to pressing a ruler into a globe). This causes the distance measurement to be shorter than the true distance, and the error becomes greater as the length of the line increases.

Diagram showing how in geographic coordinate space, a planar measurement cuts through the curved surface of the earth

Planar measurements using a projected coordinate system are like placing a ruler on a paper map. In this case, the properties of the underlying projection influence the accuracy of measurements in a given area. A Web Mercator projection, for example, exaggerates areas of the map that are not near the equator. Measurements will, therefore, be most accurate near the equator and error will increase as you move toward the poles. Planar measurements are generally best if made over small areas in a suitable spatial reference, such as the correct UTM zone for the area.

Measurements relative to a curved surface (nonplanar) are generically referred to as geodetic. Although not an exact representation of the earth, and measurements do not follow actual features on the surface (terrain, in other words), geodetic measurements are more accurate than planar measurements, especially over long distances.

For example, the following image shows distance measurements between Reykjavik and Saint Petersburg in a Web Mercator map. The red line is a planar measurement and the light gray line is geodetic. If a similar measurement were made near the equator, the values would be much closer.

Graphic showing planar versus geodetic measurements between two locations

The following are a variety of geodetic measurement types:

  • Great circle—Any circle or near circle produced by the intersection of the surface of a sphere and a flat plane that passes through the center of the sphere. The equator and all lines of longitude are great circles. Great circles are used in navigation, since the shortest path between two points on the earth's surface lies on a great circle.

  • Geodesic—The shortest distance between two points on the surface of a spheroid (also known as an ellipsoid). For example, the shortest path between two points along a meridian form a geodesic. This is similar to the great circle method, which models the surface as a sphere.

  • Normal section—A normal section is a simplified version of a geodesic line. It's defined by the intersection of a plane that passes through two points on the surface of the spheroid and is perpendicular to the surface (normal) at the first point.

  • Loxodrome—A line between two locations at a constant bearing is known as a loxodrome (or rhumb line). Loxodromes do not attempt to calculate the shortest distance since the line between the points is defined by the bearing. However, they have historical significance for nautical navigation, where a ship or plane could follow a constant compass bearing from one point to another. Only when a loxodrome is oriented precisely north-south or east-west does it define a geodesic (shortest path) line.

The geodetic methods described previously account for the earth's curvature, which makes them well-suited for nautical and aeronautical routes. However, they ignore surface topography and thus are not ideal for measuring land travel over terrain with a lot of relief. Surficial measurement, on the other hand, can be used to measure distance as it would be traveled along the terrain. With ArcGIS Pro and ArcGIS Desktop, for example, you can use the Add surface information tool to add length or area fields to a vector dataset whose values are calculated from an input elevation surface. Geoprocessing also provides a way to implement custom measurement tools.

Similarly, calculating routes along a transportation network is the most accurate way to measure travel (distance and time) over roads or trails. For information about modeling travel across a network, see Route and directions.

Use the geometry engine to make measurements

GeometryEngine provides several methods for making planar or geodetic measurements of distance or area. These measurements are made independent of the display (no map or scene is necessary). Planar measurements use the spatial reference and units of the input geometry. Even if in a geographic coordinate system, planar measurements do not consider the curvature of the earth and will return values in decimal degrees. You should therefore project the geometry you want to measure into an appropriate projected coordinate system before making planar measurements.

The geometry engine methods area(), GeometryEngine.distanceOrNull(), length() calculate planar measurements. They have the geodetic equivalents areaGeodetic(), GeometryEngine.distanceGeodeticOrNull(), and lengthGeodetic(). If a geometry engine method doesn't contain the word geodetic, you can assume it's a planar operation.

The following code makes a planar distance measurement between Edinburgh and Dar es Salaam. The input locations are first projected to a world equidistant projection.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
// Define geographic map points for the cities of Edinburgh (Scotland) and Dar es Salaam (Tanzania).
val edinburghGeographic = Point(-3.1883, 55.9533, 0.0, SpatialReference.wgs84())
val darEsSalaamGeographic = Point(39.2083, -6.7924, 0.0, SpatialReference.wgs84())

// Create a world equidistant cylindrical spatial reference for measuring planar distance.
val equidistantSpatialRef = SpatialReference(54002)

// Project the points from geographic to the projected coordinate system.
val edinburghProjected =
    GeometryEngine.projectOrNull(edinburghGeographic, equidistantSpatialRef)
        ?: return logErr("Unable to project edinburghGeographic point.")
val darEsSalaamProjected =
    GeometryEngine.projectOrNull(darEsSalaamGeographic, equidistantSpatialRef)
        ?: return logErr("Unable to project darEsSalaamGeographic point.")

// Get the planar distance between the points in the spatial reference unit (meters).
val planarDistanceMeters =
    GeometryEngine.distanceOrNull(edinburghProjected, darEsSalaamProjected)
        ?: return logErr("Unable to calculate simple planar distance between edinburghProjected and darEsSalaamProjected.")
// Result = 7,372,671.29511302 (around 7,372.67 kilometers)

When making geodetic measurements with the geometry engine, the type of geodetic measurement can be specified: geodesic, great elliptic, normal section, or loxodrome.

The following code illustrates making several geodetic distance measurements between Edinburgh and Dar es Salaam. The result of each measurement is shown in the comments at the end. With the exception of loxodrome, the values are within a meter. Compare these to the planar result, which is nearly 600 kilometers shorter.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
// Get the geodesic measurement between the points in kilometers.
val geodesicMeasureResult = GeometryEngine.distanceGeodeticOrNull(
    point1 = edinburghGeographic,
    point2 = darEsSalaamGeographic,
    distanceUnit = LinearUnit(LinearUnitId.Kilometers),
    azimuthUnit = AngularUnit(AngularUnitId.Degrees),
    curveType = GeodeticCurveType.Geodesic
)
    ?: return logErr("Unable to get geodesic measurement between edinburghGeographic and darEsSalaamGeographic.")

// Get the great elliptic measurement between the points in kilometers.
val greatEllipticMeasureResult = GeometryEngine.distanceGeodeticOrNull(
    point1 = edinburghGeographic,
    point2 = darEsSalaamGeographic,
    distanceUnit = LinearUnit(LinearUnitId.Kilometers),
    azimuthUnit = AngularUnit(AngularUnitId.Degrees),
    curveType = GeodeticCurveType.GreatElliptic
)
    ?: return logErr("Unable to get great elliptic measurement between edinburghGeographic and darEsSalaamGeographic.")

// Get the normal section measurement between the points in kilometers.
val normalSectionResult = GeometryEngine.distanceGeodeticOrNull(
    point1 = edinburghGeographic,
    point2 = darEsSalaamGeographic,
    distanceUnit = LinearUnit(LinearUnitId.Kilometers),
    azimuthUnit = AngularUnit(AngularUnitId.Degrees),
    curveType = GeodeticCurveType.NormalSection
)
    ?: return logErr("Unable to get the normal section measurement between edinburghGeographic and darEsSalaamGeographic.")

// Get the loxodrome measurement between the points in kilometers.
val loxodromeMeasureResult = GeometryEngine.distanceGeodeticOrNull(
    point1 = edinburghGeographic,
    point2 = darEsSalaamGeographic,
    distanceUnit = LinearUnit(LinearUnitId.Kilometers),
    azimuthUnit = AngularUnit(AngularUnitId.Degrees),
    curveType = GeodeticCurveType.Loxodrome
) ?: return logErr("Unable to get the loxodrome measurement between the points.")

// Measurement results:
// - geodesicMeasureResult.Distance = 7,965.9256 Km
// - greatEllipticMeasureResult.Distance = 7,965.9265 Km
// - normalSectionResult.Distance = 7,965.9264 Km
// - loxodromeMeasureResult.Distance = 8,008.0699 Km

A geodetic distance measurement result provides the following information:

  • Azimuth1—Azimuth from the first location toward the second. This value is in the chosen angular unit.
  • Azimuth2—Azimuth from the second location toward the first. This value is in the chosen angular unit.
  • Azimuth unit—Angular unit used to measure the azimuth values between input locations.
  • Distance—Geodetic distance value between the input locations. This value is in the chosen linear unit.
  • Distance unit—Linear unit used to measure the distance between input locations, such as meters, feet, kilometers, miles, and so on.

The geometry engine can also calculate geodetic area measurements and buffers. The following image shows geodetic (red) and planar (blue) polygons (appearing as discs), produced by buffering at a standard distance. In this Web Mercator projection, the geodesic polygons appear larger as you move away from the equator, however the amount of area they contain is the same. Some projections can distort area, especially as you move away from the parallel or meridian on which they're based (the equator in this example) and, therefore, may not be suited for planar measurements.

Graphic showing planar and geodesic buffer polygons of the same size

Use location distance measurement analysis in a scene view

Analysis and AnalysisOverlay classes provide fast and dynamic analysis results in a scene view. The analysis classes allow you to define analyses (such as viewshed, line of sight, and measure) that use data in the current scene and render results dynamically in the view. Analysis results are displayed using an AnalysisOverlay in a scene view. For more information about working with analysis overlays, see Manage analysis with analysis overlays.

You can use the LocationDistanceMeasurement analysis class to make interactive distance measurements between two locations in the scene view. Because the input locations are 3D points, you can measure between locations on, above, or below the surface.

A location distance measurement returns the following distances:

  • Direct distance—The straight-line distance between the start and end locations
  • Horizontal distance—The planar distance between the start and end locations as projected onto the surface of the earth
  • Vertical distance—The difference in elevation (z-value) between the start and end locations

As you update the measurement end location (perhaps by dragging on the display), the analysis displays a graphic with lines for direct, horizontal, and vertical measurements.

3D scene view showing location distance measurements (direct, horizontal, and vertical)

Use the following steps to add a location distance measurement analysis to a scene view:

  1. Create a new LocationDistanceMeasurement and set the start and end locations. These locations must be defined using 3D points (those with x-, y-, and z-coordinate values). To allow the user to define these points interactively, you can define the locations from tap events on the scene view.

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    // Create the scene analysis measure tool and provide the start and end location points.
    val distanceMeasurement = LocationDistanceMeasurement(cityCenterPoint, roofTopPoint)
    
  2. Set the unit system for distance results: metric (meters and kilometers) or imperial (feet and miles).

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    // Set the unit system for the measurements (metric or imperial).
    distanceMeasurement.unitSystem = UnitSystem.Metric
    
  3. Handle the measurement-changed event. When the measurement changes, you can read updated distances. Measurement values will be in the appropriate unit (for the chosen unit system), depending on the length: meters or feet for shorter measurements (under 3,000 meters or 1,000 feet) and kilometers or miles for those that are longer.

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    // Handle the MeasurementChanged event for the measurement analysis.
    lifecycleScope.launch {
        distanceMeasurement.measurementChanged.collect { ldmChanged ->
            // Strings to report each distance.
            val directDistanceText: String
            val horizontalDistanceText: String
            val verticalDistanceText: String
    
            // Create a formatted string that shows the direct distance value and units.
            val directDistanceValue = (ldmChanged.directDistance).value
            val directDistanceUnit = (ldmChanged.directDistance).unit.abbreviation
            directDistanceText =
                "Direct distance is ${"%.1f".format(directDistanceValue)} $directDistanceUnit"
    
            // Create a formatted string that shows the horizontal distance value and units.
            val horizontalDistanceValue = (ldmChanged.horizontalDistance).value
            val horizontalDistanceUnit = (ldmChanged.horizontalDistance).unit.abbreviation
            horizontalDistanceText =
                "Horizontal distance is ${"%.1f".format(horizontalDistanceValue)} $horizontalDistanceUnit"
    
            // Create a formatted string that shows the vertical distance value and units.
            val verticalDistanceValue = ldmChanged.verticalDistance.value
            val verticalDistanceUnit = ldmChanged.verticalDistance.unit.abbreviation
            verticalDistanceText =
                "Vertical distance is ${"%.1f".format(verticalDistanceValue)} $verticalDistanceUnit"
    
            // Show the distances in the UI.
            updateDirectDistanceUi(directDistanceText)
            updateHorizontalDistanceUi(horizontalDistanceText)
            updateVerticalDistanceUi(verticalDistanceText)
        }
    }
    
  4. Create an AnalysisOverlay with the location distance measurement and add it to the scene view. The distances are not initialized or updated unless the location distance measurement analysis is in an analysis overlay in the scene view's analysis overlay collection.

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    // Create an analysis overlay.
    val sceneAnalysisOverlay = AnalysisOverlay()
    
    // Add the LocationDistanceMeasurement to the analysis overlay.
    sceneAnalysisOverlay.analyses.add(distanceMeasurement)
    analysisOverlays.add(sceneAnalysisOverlay)
    

You can add several distance measurement analyses to a scene view and manage their visibility by turning them on or off.

3D scene view showing multiple location distance measurement analyses

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.