Git Product home page Git Product logo

com.kit.cordova.amaplocation's Introduction

com.kit.cordova.amaplocation-liugogal

使用高德Android定位SDK进行定位,以解决webapp中定位不准的问题

安装

cordova plugin add com.kit.cordova.amaplocation-liugogal --variable API_KEY=XXXXXXXXX --save

cordova plugin add https://github.com/liugogal/com.kit.cordova.amaplocation --variable API_KEY=XXXXXXXXX --save

ps:API_KEY为在高德申请的key值

ps:此插件android定位功能使用高德定位,ios定位功能使用苹果系统自带的定位功能,所以只需要配置android key,不需要配置ios key

ionic1调用方法

document.addEventListener('deviceready', function(){
	window.LocationPlugin.getLocation(successCallback,errorCallback);
}, false);

function successCallback(data) {
	//data.longitude 经度
	//data.latitude 纬度
	//data.accuracy 返回定位精度半径
	//data.address 返回地址的详细描述,包括省、市、区和街道
	//data.floor 返回定位到的室内地图的楼层,如果不在室内或者无数据,则返回默认值null。
	//data.province 返回定位位置的提供者名称。
	//data.road 返回定位信息中道路名称,如“阜荣街”。
	//data.speed 返回定位速度 ,单位:米/秒,如果此位置不具有速度,则返回0.0 。
	//data.time 返回定位时间 ,毫秒时间(距离1970年 1月 1日 00:00:00 GMT的时间)
	//data.hasAccuracy 获取定位精度状态

}

function errorCallback(msg) {
    //高德定位SDK返回的错误代码编号

    //响应码	说明
    //0	正常,有返回结果
    //21	IO 操作异常
    //22	连接异常
    //23	连接超时
    //24	无效的参数
    //25	空指针异常
    //26	url 异常
    //27	未知主机
    //28	连接服务器失败
    //29	通信协议解析错误
    //30	http 连接失败
    //31	未知的错误
    //32	keykey 鉴权验证失败,请检查key绑定的sha1值、packageName与apk是否对应
    //33	没有获取到定位权限,导致定位失败,请告知用户授予定位权限
    //34	无法获取城市信息
	console.log("错误消息:"+msg);
}

ionic2调用方法

import {Injectable} from '@angular/core';
declare var LocationPlugin;

@Injectable()
export class NativeService {
  constructor() { }
  /**
   * 获得用户当前坐标
   * @return {Promise<any>}
   */
  getUserLocation(): Promise<any> {
    return new Promise((resolve) => {
        LocationPlugin.getLocation(data => {
          resolve({'lng': data.longitude, 'lat': data.latitude});
        }, msg => {
          alert(msg.indexOf('缺少定位权限') == -1 ? ('错误消息:' + msg) : '缺少定位权限,请在手机设置中开启');
        });
    });
  }
}

com.kit.cordova.amaplocation's People

Contributors

xiaosan666 avatar liugogal avatar

Stargazers

K68 avatar  avatar wangtao avatar  avatar

Watchers

 avatar

com.kit.cordova.amaplocation's Issues

IOS权限申请不符

定位权限申请描述不符

插件的plugin.xml定义如下:

<config-file target="*/*-Info.plist" parent="UIBackgroundModes">
	<array>
		<string>location</string>
	</array>
</config-file>
<config-file target="*/*-Info.plist" parent="NSLocationAlwaysUsageDescription">
	<string>为了确保您可以正确使用本应用,请选择允许</string>
</config-file>

可插件的运行机制貌似是需要的时候才获取定位,并没有持续获取定位,是不是应该做如下修改

  1. 去除UIBackgroundModes的权限申请
  2. 将NSLocationAlwaysUsageDescription 改为NSLocationWhenInUseUsageDescription

在android上没有出现问题,可上架IOS app store的时候被拒绝了,apple的说明是申请了UIBackgroundModes -> location 可没有对应的功能

因为不是IOS开发人员,被这个问题折腾老久,现在IOS还没有上架,求作者好心解答下,谢谢了!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.