---
title: Class: GeoPoint
source: https://vjmap.com/doc/Class_GeoPoint.html
---

# Class: GeoPoint

`GeoPoint` 地理坐标.

### Table of contents

#### Constructors

- [constructor](#constructor)

#### Properties

- [x](#x)
- [y](#y)
- [z](#z)

#### Methods

- [add](#add)
- [angle](#angle)
- [angleTo](#angleto)
- [angleWith](#anglewith)
- [angleWithSep](#anglewithsep)
- [clone](#clone)
- [distSqr](#distsqr)
- [distanceTo](#distanceto)
- [div](#div)
- [divByPoint](#divbypoint)
- [dot](#dot)
- [equals](#equals)
- [equalsZ](#equalsz)
- [lengthSq](#lengthsq)
- [lerp](#lerp)
- [mag](#mag)
- [matMult](#matmult)
- [mult](#mult)
- [multByPoint](#multbypoint)
- [perp](#perp)
- [roateAround](#roatearound)
- [rotate](#rotate)
- [round](#round)
- [roundInt](#roundint)
- [roundStr](#roundstr)
- [sub](#sub)
- [toArray](#toarray)
- [toString](#tostring)
- [transform](#transform)
- [unit](#unit)
- [convert](#convert)
- [fromString](#fromstring)

### Constructors

#### constructor

\+ **new GeoPoint**(`x`: *number*, `y`: *number*, `z?`: *number*): [*GeoPoint*](#classesdefaultgeopointmd)

 `GeoPoint` 构造函数

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | *number* | x坐标. |
| `y` | *number* | y坐标. |
| `z?` | *number* | z坐标(可选）. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

### Properties

#### x

• **x**: *number*

坐标X.

___

#### y

• **y**: *number*

坐标y.

___

#### z

• `Optional` **z**: *number*

坐标z(可选）.

### Methods

#### add

▸ **add**(`p`: [*GeoPoint*](#classesdefaultgeopointmd)): [*GeoPoint*](#classesdefaultgeopointmd)

两个点相加.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `p` | [*GeoPoint*](#classesdefaultgeopointmd) | 要相加的点. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### angle

▸ **angle**(): *number*

角度.

**Returns:** *number*

___

#### angleTo

▸ **angleTo**(`b`: [*GeoPoint*](#classesdefaultgeopointmd)): *number*

距一个点的角度

##### Parameters

| Name | Type |
| :------ | :------ |
| `b` | [*GeoPoint*](#classesdefaultgeopointmd) |

**Returns:** *number*

___

#### angleWith

▸ **angleWith**(`b`: [*GeoPoint*](#classesdefaultgeopointmd)): *number*

距一个点的interiorAngle

##### Parameters

| Name | Type |
| :------ | :------ |
| `b` | [*GeoPoint*](#classesdefaultgeopointmd) |

**Returns:** *number*

___

#### angleWithSep

▸ **angleWithSep**(`x`: *number*, `y`: *number*): *number*

距一个点的interiorAngle

##### Parameters

| Name | Type |
| :------ | :------ |
| `x` | *number* |
| `y` | *number* |

**Returns:** *number*

___

#### clone

▸ **clone**(): [*GeoPoint*](#classesdefaultgeopointmd)

 克隆一个坐标

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### distSqr

▸ **distSqr**(`p`: [*GeoPoint*](#classesdefaultgeopointmd)): *number*

两点之间距离平方.

##### Parameters

| Name | Type |
| :------ | :------ |
| `p` | [*GeoPoint*](#classesdefaultgeopointmd) |

**Returns:** *number*

___

#### distanceTo

▸ **distanceTo**(`p`: [*GeoPoint*](#classesdefaultgeopointmd)): *number*

两点之间距离.

##### Parameters

| Name | Type |
| :------ | :------ |
| `p` | [*GeoPoint*](#classesdefaultgeopointmd) |

**Returns:** *number*

___

#### div

▸ **div**(`k`: *number*): [*GeoPoint*](#classesdefaultgeopointmd)

除一个系数.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `k` | *number* | 系数. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### divByPoint

▸ **divByPoint**(`p`: [*GeoPoint*](#classesdefaultgeopointmd)): [*GeoPoint*](#classesdefaultgeopointmd)

两个点相除.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `p` | [*GeoPoint*](#classesdefaultgeopointmd) | 要相除的点. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### dot

▸ **dot**(`p`: [*GeoPoint*](#classesdefaultgeopointmd)): *number*

##### Parameters

| Name | Type |
| :------ | :------ |
| `p` | [*GeoPoint*](#classesdefaultgeopointmd) |

**Returns:** *number*

___

#### equals

▸ **equals**(`other`: [*GeoPoint*](#classesdefaultgeopointmd), `dotErr?`: *number*): *boolean*

判断是否相等

##### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `other` | [*GeoPoint*](#classesdefaultgeopointmd) | - | 另外一个点 |
| `dotErr` | *number* | 8 | 允许误差的小数点后几位，默认8位 |

**Returns:** *boolean*

___

#### equalsZ

▸ **equalsZ**(`other`: [*GeoPoint*](#classesdefaultgeopointmd)): *boolean*

是否相等（判断z).

##### Parameters

| Name | Type |
| :------ | :------ |
| `other` | [*GeoPoint*](#classesdefaultgeopointmd) |

**Returns:** *boolean*

___

#### lengthSq

▸ **lengthSq**(): *number*

**Returns:** *number*

___

#### lerp

▸ **lerp**(`v`: [*GeoPoint*](#classesdefaultgeopointmd), `alpha`: *number*): [*GeoPoint*](#classesdefaultgeopointmd)

##### Parameters

| Name | Type |
| :------ | :------ |
| `v` | [*GeoPoint*](#classesdefaultgeopointmd) |
| `alpha` | *number* |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### mag

▸ **mag**(): *number*

长度.

**Returns:** *number*

___

#### matMult

▸ **matMult**(`m`: *number*[]): [*GeoPoint*](#classesdefaultgeopointmd)

乘一个矩阵.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `m` | *number*[] | 矩阵值. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### mult

▸ **mult**(`k`: *number*): [*GeoPoint*](#classesdefaultgeopointmd)

乘一个系数.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `k` | *number* | 系数. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### multByPoint

▸ **multByPoint**(`p`: [*GeoPoint*](#classesdefaultgeopointmd)): [*GeoPoint*](#classesdefaultgeopointmd)

两个点相乘.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `p` | [*GeoPoint*](#classesdefaultgeopointmd) | 要相乘的点. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### perp

▸ **perp**(): [*GeoPoint*](#classesdefaultgeopointmd)

投影 [x,y] = [-y, x].

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### roateAround

▸ **roateAround**(`angle`: *number*, `p`: [*GeoPoint*](#classesdefaultgeopointmd)): [*GeoPoint*](#classesdefaultgeopointmd)

绕一个点旋转.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `angle` | *number* | 弧度. |
| `p` | [*GeoPoint*](#classesdefaultgeopointmd) | 围绕的点. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### rotate

▸ **rotate**(`angle`: *number*): [*GeoPoint*](#classesdefaultgeopointmd)

旋转.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `angle` | *number* | 弧度. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### round

▸ **round**(`fixed?`: *number*): [*GeoPoint*](#classesdefaultgeopointmd)

后小数点几位取整

##### Parameters

| Name | Type | Default value |
| :------ | :------ | :------ |
| `fixed` | *number* | 6 |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### roundInt

▸ **roundInt**(): [*GeoPoint*](#classesdefaultgeopointmd)

四舍五入取整.

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### roundStr

▸ **roundStr**(`fixed?`: *number*): *string*

##### Parameters

| Name | Type | Default value |
| :------ | :------ | :------ |
| `fixed` | *number* | 6 |

**Returns:** *string*

___

#### sub

▸ **sub**(`p`: [*GeoPoint*](#classesdefaultgeopointmd)): [*GeoPoint*](#classesdefaultgeopointmd)

两个点相减.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `p` | [*GeoPoint*](#classesdefaultgeopointmd) | 要相减的点. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### toArray

▸ **toArray**(): *number*[]

返回数组

**Returns:** *number*[]

The coordinates represeted as an array of x and y.
```typescript
var ll = new vjmap.GeoPoint(-73.9749, 40.7736);
ll.toArray(); // = [-73.9749, 40.7736]
```

___

#### toString

▸ **toString**(`fixed?`: *number*): *string*

返回字符串.

##### Parameters

| Name | Type | Default value |
| :------ | :------ | :------ |
| `fixed` | *number* | 6 |

**Returns:** *string*

The coordinates represented as a string of the format `'x, y, z?'`.
```typescript
var ll = new vjmap.GeoPoint(-73.9749, 40.7736);
ll.toString(); // = "GeoPoint(-73.9749, 40.7736)"
```

___

#### transform

▸ **transform**(`basePt`: [*GeoPoint*](#classesdefaultgeopointmd), `destPt`: [*GeoPoint*](#classesdefaultgeopointmd), `scale?`: *number*, `angle?`: *number*): [*GeoPoint*](#classesdefaultgeopointmd)

对一个点围绕一个基点进行缩放旋转平移操作.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `basePt` | [*GeoPoint*](#classesdefaultgeopointmd) | 围绕的基点坐标 |
| `destPt` | [*GeoPoint*](#classesdefaultgeopointmd) | 要平移至的目的地坐标 |
| `scale?` | *number* | 缩放比例，默认1.0 |
| `angle?` | *number* | 旋转角度，逆时针，默认0 |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### unit

▸ **unit**(): [*GeoPoint*](#classesdefaultgeopointmd)

单位长度.

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### convert

▸ `Static` **convert**(`input`: [*GeoPointLike*](#geopointlike)): [*GeoPoint*](#classesdefaultgeopointmd)

根据不同的类型创建地理坐标 [GeoPoint](#classesdefaultgeopointmd) .

Example:
```typescript
const p1 = GeoPoint.convert(new GeoPoint(x, y, z));
const p2 = GeoPoint.convert([x, y]);
const p3 = GeoPoint.convert([x, y, z]);
const p4 = GeoPoint.convert(lng: -73.9749, lat: 40.7736});
const p5 = GeoPoint.convert(lon: -73.9749, lat: 40.7736});
```

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `input` | [*GeoPointLike*](#geopointlike) | Either [GeoPointLike](#geopointlike), [GeoPointLike](#geopointlike) or [GeoPointLike](#geopointlike) object literal. |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)

___

#### fromString

▸ `Static` **fromString**(`input`: *string*): [*GeoPoint*](#classesdefaultgeopointmd)

根据字符串创建 `GeoPoint`.

Example:
```typescript
const b = GeoPoint.fromString("1,2");
```

##### Parameters

| Name | Type |
| :------ | :------ |
| `input` | *string* |

**Returns:** [*GeoPoint*](#classesdefaultgeopointmd)


<a name="classesgeoprojectionmd"></a>

[vjmap](#readmemd) / [Exports](#modulesmd) / GeoProjection
