@Plugin({
pluginName: 'BaiduLocation',
plugin: 'cordova-plugin-baidumaplocation', // npm package name, example: cordova-plugin-camera
pluginRef: 'cordova.plugins.baidumap_location', // the variable reference to call the plugin, example: navigator.geolocation
repo: 'https://github.com/aruis/cordova-plugin-baidumaplocation.git', // the github repository URL for the plugin
install: 'ionic cordova plugin add https://github.com/aruis/cordova-plugin-baidumaplocation.git --variable ANDROID_KEY=your android key --variable IOS_KEY=your ios key', // OPTIONAL install command, in case the plugin requires variables
installVariables: ['ANDROID_KEY' , 'IOS_KEY'] , // OPTIONAL the plugin requires variables
platforms: ['Android' , 'iOS'] // Array of platforms supported, example: ['Android', 'iOS']
})
@Injectable()
export class BaiduLocation extends IonicNativePlugin {
/**
This function does something
@param arg1 {string} Some param to configure something
@param arg2 {number} Another param to configure something
@return {Promise} Returns a promise that resolves when something happens
*/
@Cordova()
getCurrentPosition(): Promise {
return; // We add return; here to avoid any IDE / Compiler errors
}
一、ionic可以添加ionic-native组件,直接在angular中使用 1.git clone https://github.com/ionic-team/ionic-native.git 2.npm install 3.gulp plugin:create -n BaiduLocation 4.编辑ionic-native/src/@ionic-native/plugins/baidu-location/index.ts import { Injectable } from '@angular/core'; import { Plugin, Cordova, CordovaProperty, CordovaInstance, InstanceProperty, IonicNativePlugin } from '@ionic-native/core'; import { Observable } from 'rxjs';
@Plugin({ pluginName: 'BaiduLocation', plugin: 'cordova-plugin-baidumaplocation', // npm package name, example: cordova-plugin-camera pluginRef: 'cordova.plugins.baidumap_location', // the variable reference to call the plugin, example: navigator.geolocation repo: 'https://github.com/aruis/cordova-plugin-baidumaplocation.git', // the github repository URL for the plugin install: 'ionic cordova plugin add https://github.com/aruis/cordova-plugin-baidumaplocation.git --variable ANDROID_KEY=your android key --variable IOS_KEY=your ios key', // OPTIONAL install command, in case the plugin requires variables installVariables: ['ANDROID_KEY' , 'IOS_KEY'] , // OPTIONAL the plugin requires variables platforms: ['Android' , 'iOS'] // Array of platforms supported, example: ['Android', 'iOS'] }) @Injectable() export class BaiduLocation extends IonicNativePlugin {
/**
}
export interface PositionOptions { time: string ; locType: string ; locTypeDescription: string ; latitude: number ; longitude: number ; countryCode: string ; country: string ; province: string ; citycode: string ; city: string ; district: string ; street: string ; addr: string ; }
5.npm run build 6.复制生成的dist/@ionic-native/baidu-location到项目下/node_modules/@ionic-native/ 7.在package中添加@ionic-native/baidu-location依赖