Easy to use, coordinate format checking tool.
npm install check-coord
-
Import the module:
const checkCoord = require('check-coord');
-
Call the function:
checkCoord(inpCoord)
, whereinpCoord
is the string to be checked. -
Return value: The function will return an object with the following properties:
isTrue
: Boolean value indicating whether the input string matches the pattern of latitude and longitude coordinates.type
: Type of the coordinate(s), which can be 'spot', 'line', or 'region'.spots
: Array of coordinate objects; only exists when type is 'spot' or 'line'. regionSpot: Number of points in the polygonal region; only exists when type is 'region'.message
: Error message; only exists when isTrue is false.
import checkCoord from "check-coord";
// Coordinate point
checkCoord("116.3978146455078,39.9076393154042");
// Coordinate line
checkCoord("116.3978146455078,39.9076393154042; 116.39652718518064,39.93344333054544");
// Coordinate region
checkCoord("116.3978146455078,39.9076393154042; 116.39652718518064,39.93344333054544; 116.41712655041502,39.93370658670286");
// Coordinate point
{
isTrue: true, // The coordinate are correct.
type: 'spot', // The coordinate type is 'point'.
// Coordinate array.
spots: [
{
lng: '116.3978146455078', // longitude
lat: '39.9076393154042' // latitude
}
]
}
// Coordinate line
{
isTrue: true,
type: 'line',
spots: [
{
lng: '116.3978146455078',
lat: '39.9076393154042'
},
{
lng: '116.39652718518064',
lat: '39.93344333054544'
}
]
}
// Coordinate region
{
isTrue: true,
type: 'region',
spots: [
{
lng: '116.3978146455078',
lat: '39.9076393154042'
},
{
lng: '116.39652718518064',
lat: '39.93344333054544'
},
{
lng: '116.41712655041502',
lat: '39.93370658670286'
}
],
regionSpot: 3 // Number of area points.
}