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

xgrn-location

v0.3.10

Published

封装高德地图定位,兼容IOS/ANDROID

Downloads

2

Readme

RN高德定位SDK介绍

  • 1.本库封装高德地图原生定位功能。RN-Js Android IOS中均可调用相关功能
  • 2.定位可能存在失败,建议失败时,业务层优先检查是否由于权限不足导致的。
  • 3.建议各位同学都能把常用的高德原生功能,很好的扩充并封装到本SDK提供给RN或原生使用。

安装说明

  • 1.yarn add xgrn-location
  • 2.react-native link xgrn-location
  • 3.原生配置IOS和安卓的相关key
  • 4.IOS中Info.plist添加Privacy - Location When In Use Usage Description 用于描述提示用户使用地位功能的原因
  • 5.IOS工程Podfile文件,添加高德地图依赖
  • 6.cd ios 然后 pod install
pod "AMapLocation-NO-IDFA"
pod "AMapNavi-NO-IDFA"

Android部分

使用说明

项目依赖该库后,需要做如下额外操作:

  • 注册高德开发者,配置应用信息获取对应的key
  • 在manifest中添加mate和service
        <meta-data android:name="com.amap.api.v2.apikey" android:value="your key" />

        <service android:name="com.amap.api.location.APSService" />

相关接口

RN调用XGLocation.js文件,通过Promise返回。

原生直接调用XGLocation类,返回一个Observable对象,通过Subscribe获取MapLocationBean。


    /**
     * 由于Android碎片化,我们无法准确获取权限,该方法暂只适应判断GPS是否打开
     * gpsPermission true:打开; false:关闭
     * appPermission true
     */
    @ReactMethod
    public void checkPermissions(final Promise promise)

    /**
     * 获取当前位置,只定位一次
     */
    @ReactMethod
    public void searchCurrentLocation(final Promise promise)

    /**
     * 跳转应用设置页,设置权限
     */
    @ReactMethod
    public void goApplicationLocationSetting()

    /**
     * 跳转系统Gps设置页
     */
    @ReactMethod
    public void goSystemLocationSetting(Promise promise)

数据格式

获取到的结果统一封装为如下格式

{
    resultCode: 0, number
    resultDesc: '',string
    resultData: {  object
    errorCode: 0,                   number 错误码
    errorMsg: '',                  string 错误描述(提示友好)
    systemErrorMsg: '',            string 错误描述-系统自带的提示(不要暴露给用户,开发自己使用或用于异常上传使用)
    appPermission: true,            bool  应用定位权限是否开启
    gpsPermission: true,            bool  系统定位权限是否开启
    latitude: '12312312.213123',    string   经纬度
    longitude: '12312312.213123',   string
    country: '中国',                 string  国家
    province: '浙江省',              string  省份
    city: '杭州市',                  string  城市
    district: '上城区',              string 区
    number: '123号',                string 门牌号
    street: '望潮路',                string  街道名称
    POIName: 'xx',                  string 兴趣点名称
    AOIName: 'xx',                  string 所属兴趣点名称
    citycode: '12',                 string 城市编号
    adcode: '123',                  string  区号
    formattedAddress: 'xxxxxxxx',   string 格式化地址
}

结果码

resultCode与errorCode一致,大部分errorCode与高德的错误码相同,参考错误码对照表

部分自定义的错误码:

  • -999 未知错误
  • -899 GPS未开启

IOS部分说明

【IOS-高德地图】 【IOS-高德错误码表】

初始化,仅支持native端配置SDK-Key

  • 1.初始化配置高德地图SDK-Key。
  • 2.调用定位。
  • 3.处理定位结果。如果出错,首先检测是否由于定位权限不足导致。
#import <XGLocationManager.h>

#pragma mark - 配置高德地图
+ (void)configurationMap {
  [[XGLocationManager shareManager] setAmapApiKey:@"f853ff869a0376aa8e61b39d1e36888f"];
}

//调用GPS定位
[[XGLocationManager shareManager] queryLocation:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error, PermissionStatus *permissionStatus) {
    if (error) {//定位失败。判断是否由于权限不足导致。
        BOOL gpsPermission = permissionStatus.gpsPermission;
        BOOL appPermission = permissionStatus.appPermission;
        //
        NSLog(@"%@",error);
    } else {
        //CLLocation 为标准高德定位结果Model
        NSLog(@"%@",location);
    }
  }];

JavaScript使用说明

import XGLocation from 'xgrn-location';
  • 1.查询权限是否开启
/**
 * 查询权限是否开启
 * @return {*}<Promise> {
 *  gpsPermission bool GPS权限是否开启
 *  appPermission bool app权限是否开启
 * }
 */
const {gpsPermission,appPermissio} = await XGLocation.checkPermissions();
  • 2.查询用户当前位置信息
/**
 * 查询用户当前位置信息
 * @return {*}<Promise> {
 *      resultCode: 0, number
 *      resultDesc: '',string
 *      resultData: {  object
 *          errorCode: 0,                   number 错误码
 *          errorMsg: '',                  string 错误描述(提示友好)
 *          systemErrorMsg: '',            string 错误描述-系统自带的提示(建议不要暴露给用户、可用于开发阶段定位失败原因或用于线上异常上传使用)
 *          appPermission: true,            bool  应用定位权限是否开启
 *          gpsPermission: true,            bool  系统定位权限是否开启
 *          latitude: '12312312.213123',    string   经纬度
 *          longitude: '12312312.213123',   string
 *          country: '中国',                 string  国家
 *          province: '浙江省',              string  省份
 *          city: '杭州市',                  string  城市
 *          district: '上城区',              string 区
 *          number: '123号',                string 门牌号
 *          street: '望潮路',                string  街道名称
 *          POIName: 'xx',                  string 兴趣点名称
 *          AOIName: 'xx',                  string 所属兴趣点名称
 *          citycode: '12',                 string 城市编号
 *          adcode: '123',                  string  区号
 *          formattedAddress: 'xxxxxxxx',   string 格式化地址
 *      }
 * 
 */
const result = await XGLocation.searchCurrentLocation();
  • 3.跳转定位权限设置页面
/**
 * 跳转定位权限设置页面
 * @param type String 设置类型
 * Enum-String 枚举字符串
 *  'GPS' GPS系统权限开关设置 ios暂不支持此跳转
 *  'APP' APP应用权限开关设
 */
XGLocation.goToPermissionsSetting(type);