ooomap-geolocation

1.0.8 • Public • Published

ooomap geolocation

方便在 ooomap SDK 中使用浏览器提供的 navigator.geolocation 获得坐标的插件

会获得3种坐标: 相对坐标(ooomap地图坐标), 墨卡托坐标, 经纬度坐标

安装

npm install ooomap-geolocation --save

引入

使用模块引入

import * as om from "ooomap"
import { GeoLocation } from "ooomap-geolocation"

也可以使用<script>标签引入此插件

创建 GeoLocation 对象

es6:

let geolocation = new GeoLocation( om )

script标签:

let geolocation = new om.GeoLocation( om )

方法

  • start

    • 开始获取位置
     geolocation.start()
  • stop

    • 终止获取位置
     geolocation.stop()

字段

是否暂停

geolocation.pause = true; 	// true or false

事件

在获取到位置后, 会触发 position 事件, 会返回3个坐标, 一个是web墨卡拖坐标{x:, y: }, 还有一个是原始的经纬度坐标{lng:, lat:}

  • 相对坐标(position): {x:, y:}
    • (墨卡托坐标) - (地图中心点center) = 相对坐标
    • 用于在 ooomap 地图中设置位置坐标
  • 墨卡托坐标(mercator): {x:, y:}
  • 经纬度坐标(lnglat): {lng:, lat:}
geolocation.on('position', (position, mercator, lnglat) => {

	console.log(position, mercator, lnglat)

})

Package Sidebar

Install

npm i ooomap-geolocation

Weekly Downloads

3

Version

1.0.8

License

ISC

Unpacked Size

3.81 kB

Total Files

3

Last publish

Collaborators

  • easyfrog