# Nearest vertex

View inWPFUWPFormsiOSAndroid
View on GitHub

Find the closest vertex and coordinate of a geometry to a point. ## Use case

Determine the shortest distance between a location and the boundary of an area. For example, developers can snap imprecise user clicks to a geometry if the tap is within a certain distance of the geometry.

## How to use the sample

Tap anywhere on the map. An orange cross will show at that location. A blue circle will show the polygon's nearest vertex to the point that was clicked. A red diamond will appear at the coordinate on the geometry that is nearest to the point that was clicked. If clicked inside the geometry, the red and orange markers will overlap. The information box showing distance between the clicked point and the nearest vertex/coordinate will be updated with every new location clicked.

## How it works

1. Get a `Geometry` and a `Point` to check the nearest vertex against.
2. Call `GeometryEngine.NearestVertex(inputGeometry, point)`.
3. Use the returned `ProximityResult` to get the `Point` representing the polygon vertex, and to determine the distance between that vertex and the clicked point.
4. Call `GeometryEngine.NearestCoordinate(inputGeometry, point)`.
5. Use the returned `ProximityResult` to get the `Point` representing the coordinate on the polygon, and to determine the distance between that coordinate and the clicked point.

## Relevant API

• GeometryEngine
• ProximityResult

## Tags

analysis, coordinate, geometry, nearest, proximity, vertex

## Sample Code

NearestVertex.xamlNearestVertex.xaml.cs

``````﻿<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="ArcGISRuntime.Samples.NearestVertex.NearestVertex"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:forms="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label
x:Name="ResultsLabel"
Grid.Row="0"
HorizontalTextAlignment="Center"
TextColor="Red">
Tap to see the nearest vertex and point.
</Label>
<forms:MapView x:Name="MyMapView" Grid.Row="1" />
</Grid>
</ContentPage>
``````