npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mars-coord

v0.0.3

Published

[![English README](https://img.shields.io/badge/README-English-green)](./README_EN.md) [![npm version](https://img.shields.io/npm/v/mars-coord.svg?style=flat)](https://www.npmjs.com/package/mars-coord) [![License: MIT](https://img.shields.io/badge/License

Downloads

8

Readme

Mars Coord

English README npm version License: MIT

这是一个用于转换火星坐标系的工具库。它使用 TypeScript 编写。

支持的坐标系统有 'WGS84','GCJ02','BD09',以及 'CGCS2000'。

同时提供了AMAP(高德地图),QQ(腾讯地图),和BAIDU(百度地图)这几个别名,分别对应 'GCJ02','GCJ02',和 'BD09'。

安装

npm install mars-coord

使用方法

import { Coordinate, convertCoordinate } from 'mars-coord';

// 创建一个坐标
const myCoordinate: Coordinate = [110.030774, 36.815854]; // 例如,这是一个 'WGS84' 坐标

// 将坐标转换为其他坐标系
const result = convertCoordinate(myCoordinate, 'WGS84');

console.log('WGS84:', result.WGS84);
console.log('GCJ02:', result.GCJ02);
console.log('AMAP:', result.AMAP); // 高德地图使用的坐标系
console.log('QQ:', result.QQ); // 腾讯地图使用的坐标系
console.log('BD09:', result.BD09);
console.log('BAIDU:', result.BAIDU); // 百度地图使用的坐标系
console.log('CGCS2000:', result.CGCS2000);

在前端中使用

import { convertCoordinate } from 'mars-coord';

// 定义一个函数,获取当前位置,并返回一个Promise
function getCurrentLocation() {
  return new Promise((resolve, reject) => {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(resolve, reject);
    } else {
      reject(new Error('此浏览器不支持地理位置。'));
    }
  });
}

// 定义一个异步函数,获取并转换坐标
async function getConvertedCoordinates() {
  try {
    // 等待获取当前位置
    const position = await getCurrentLocation();
    const myCoordinate = [position.coords.longitude, position.coords.latitude];

    // 使用mars-coord将坐标转换为其他坐标系
    const result = convertCoordinate(myCoordinate, 'WGS84');

    console.log('WGS84:', result.WGS84); // 输出WGS84坐标
    console.log('GCJ02:', result.GCJ02); // 输出GCJ02坐标
    console.log('AMAP:', result.AMAP); // 输出高德地图使用的坐标
    console.log('QQ:', result.QQ); // 输出QQ地图使用的坐标
    console.log('BD09:', result.BD09); // 输出BD09坐标
    console.log('BAIDU:', result.BAIDU); // 输出百度地图使用的坐标
    console.log('CGCS2000:', result.CGCS2000); // 输出CGCS2000坐标
  } catch (error) {
    // 处理任何错误
    console.error('发生错误:', error);
  }
}

// 调用函数执行代码
getConvertedCoordinates();

坐标拾取器

License

This project is licensed under the terms of the MIT license.