@axolo/egg-amap

0.0.2 • Public • Published

egg-amap

AMap WEB Service API for Egg.js plugin.

Install

npm i @axolo/egg-amap --save

Usage

// {app_root}/config/plugin.js
exports.amap = {
  enable: true,
  package: '@axolo/egg-amap',
};

Configuration

// {app_root}/config/config.default.js
const axios = require('axios');
exports.amap = {
  // axios: axios.create({ baseURL: 'https://restapi.amap.com' }),
  key: 'AMAP-APP-KEY',
};

see config/config.default.js for more detail.

Example

'use strict';

const Controller = require('egg').Controller;

class AmapController extends Controller {
  async index() {
    const { app, ctx } = this;
    const amap = app.amap; // axios instance
    const { keywords } = ctx.request.query;
    // https://lbs.amap.com/api/webservice/guide/api/newpoisearch
    const result = await amap.get('/v5/place/text', { params: { keywords } });
    ctx.body = result?.data;
  }
}

module.exports = AmapController;

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i @axolo/egg-amap

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

5.51 kB

Total Files

6

Last publish

Collaborators

  • axolo