capacitor-ionic-plugin-amap
v7.0.4
Published
Amap Capacitor
Downloads
18
Readme
capacitor-ionic-plugin-amap
Amap Capacitor
基于https://github.com/yilifangteam/capacitor-ionic-plugin-amap修改最新版本
大版本跟@capacitor
v7.x support
Capacitor 7
Install
npm install capacitor-ionic-plugin-amap
npx cap syncIOS
配置IOS_KEY IOS安装插件后,需在项目的capacitor.config.ts/capacitor.config.json中为项目配置IOS_KEY
const config: CapacitorConfig = {
plugins: {
AMap: {
iosKey: "your key",
},
}
};xcode16,需要安装Rosetta2
# 安装 Rosetta, 模拟器运行需要选择rosetta版本
/usr/sbin/softwareupdate --install-rosetta --agree-to-licenseIOS安装插件后,需在XCODE的info.plist中为项目配置以下内容
<key>NSLocationWhenInUseUsageDescription</key>
<string>此应用需要定位权限才能正常使用</string>Android
add the following to your app's build.gradle:
// 这里sdk获取方式不能用这种填充,可以忽略这步,内部实现会自动处理appkey
manifestPlaceholders = [
AMAP_APPKEY: "map key",
]API
init()
init() => voidlocate()
locate() => Promise<Location | undefined>Returns: Promise<Location>
weather(...)
weather(param: { adCode: string; }) => Promise<WeatherInfo | undefined>| Param | Type |
| ----------- | -------------------------------- |
| param | { adCode: string; } |
Returns: Promise<WeatherInfo>
calculate(...)
calculate(params: { startLatitude: number; startLongitude: number; endLatitude: number; endLongitude: number; }) => Promise<{ distance: number; } | undefined>| Param | Type |
| ------------ | ---------------------------------------------------------------------------------------------------------- |
| params | { startLatitude: number; startLongitude: number; endLatitude: number; endLongitude: number; } |
Returns: Promise<{ distance: number; }>
Interfaces
Location
| Prop | Type | Description |
| ------------------ | ------------------------------------- | ----------- |
| accuracy | number | 定位精度 |
| adCode | string | 区域编码 |
| address | string | 地址 |
| city | string | 城市|区 |
| cityCode | string | 城市编码 |
| latitude | number | 精度 |
| longitude | number | 纬度 |
| aoiName | string | 当前定位点的AOI信息 |
| country | string | 国家 |
| district | string | 城区信息 |
| poiName | string | 当前定位点的POI信息 |
| province | string | 省份 |
| street | string | 街道 |
| streetNum | string | 街道号 |
| locationTime | Date | 定位时间 |
Date
Enables basic storage and retrieval of dates and times.
| Method | Signature | Description | | ---------------------- | ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- | | toString | () => string | Returns a string representation of a date. The format of the string depends on the locale. | | toDateString | () => string | Returns a date as a string value. | | toTimeString | () => string | Returns a time as a string value. | | toLocaleString | () => string | Returns a value as a string value appropriate to the host environment's current locale. | | toLocaleDateString | () => string | Returns a date as a string value appropriate to the host environment's current locale. | | toLocaleTimeString | () => string | Returns a time as a string value appropriate to the host environment's current locale. | | valueOf | () => number | Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. | | getTime | () => number | Gets the time value in milliseconds. | | getFullYear | () => number | Gets the year, using local time. | | getUTCFullYear | () => number | Gets the year using Universal Coordinated Time (UTC). | | getMonth | () => number | Gets the month, using local time. | | getUTCMonth | () => number | Gets the month of a Date object using Universal Coordinated Time (UTC). | | getDate | () => number | Gets the day-of-the-month, using local time. | | getUTCDate | () => number | Gets the day-of-the-month, using Universal Coordinated Time (UTC). | | getDay | () => number | Gets the day of the week, using local time. | | getUTCDay | () => number | Gets the day of the week using Universal Coordinated Time (UTC). | | getHours | () => number | Gets the hours in a date, using local time. | | getUTCHours | () => number | Gets the hours value in a Date object using Universal Coordinated Time (UTC). | | getMinutes | () => number | Gets the minutes of a Date object, using local time. | | getUTCMinutes | () => number | Gets the minutes of a Date object using Universal Coordinated Time (UTC). | | getSeconds | () => number | Gets the seconds of a Date object, using local time. | | getUTCSeconds | () => number | Gets the seconds of a Date object using Universal Coordinated Time (UTC). | | getMilliseconds | () => number | Gets the milliseconds of a Date, using local time. | | getUTCMilliseconds | () => number | Gets the milliseconds of a Date object using Universal Coordinated Time (UTC). | | getTimezoneOffset | () => number | Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC). | | setTime | (time: number) => number | Sets the date and time value in the Date object. | | setMilliseconds | (ms: number) => number | Sets the milliseconds value in the Date object using local time. | | setUTCMilliseconds | (ms: number) => number | Sets the milliseconds value in the Date object using Universal Coordinated Time (UTC). | | setSeconds | (sec: number, ms?: number | undefined) => number | Sets the seconds value in the Date object using local time. | | setUTCSeconds | (sec: number, ms?: number | undefined) => number | Sets the seconds value in the Date object using Universal Coordinated Time (UTC). | | setMinutes | (min: number, sec?: number | undefined, ms?: number | undefined) => number | Sets the minutes value in the Date object using local time. | | setUTCMinutes | (min: number, sec?: number | undefined, ms?: number | undefined) => number | Sets the minutes value in the Date object using Universal Coordinated Time (UTC). | | setHours | (hours: number, min?: number | undefined, sec?: number | undefined, ms?: number | undefined) => number | Sets the hour value in the Date object using local time. | | setUTCHours | (hours: number, min?: number | undefined, sec?: number | undefined, ms?: number | undefined) => number | Sets the hours value in the Date object using Universal Coordinated Time (UTC). | | setDate | (date: number) => number | Sets the numeric day-of-the-month value of the Date object using local time. | | setUTCDate | (date: number) => number | Sets the numeric day of the month in the Date object using Universal Coordinated Time (UTC). | | setMonth | (month: number, date?: number | undefined) => number | Sets the month value in the Date object using local time. | | setUTCMonth | (month: number, date?: number | undefined) => number | Sets the month value in the Date object using Universal Coordinated Time (UTC). | | setFullYear | (year: number, month?: number | undefined, date?: number | undefined) => number | Sets the year of the Date object using local time. | | setUTCFullYear | (year: number, month?: number | undefined, date?: number | undefined) => number | Sets the year value in the Date object using Universal Coordinated Time (UTC). | | toUTCString | () => string | Returns a date converted to a string using Universal Coordinated Time (UTC). | | toISOString | () => string | Returns a date as a string value in ISO format. | | toJSON | (key?: any) => string | Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. |
WeatherInfo
| Prop | Type | Description |
| ------------------- | --------------------------------- | ----------- |
| type | 'live' | 'forecast' | |
| weather | string | 天气 |
| temperature | string | 温度 |
| city | string | 城市|区 |
| province | string | 省份 |
| windDirection | string | 风向 |
| windPower | string | 风力 |
| humidity | string | 湿度 |
DEMO
// location.service.ts import { Injectable } from '@angular/core'; import { Platform } from '@ionic/angular'; import { Helper } from '../helper'; import { AMap } from 'capacitor-ionic-plugin-amap'; @Injectable({ providedIn: 'root' }) export class LocationService { constructor(private platform: Platform, private helper: Helper) { AMap.init(); }
async getCurrentPosition() {
await this.platform.ready();
try {
const position = await AMap.locate();
return position;
} catch (err) {
console.error('获取位置失败:', err);
throw err;
}
}
async getWeather(adCode: string) {
await this.platform.ready();
try {
const position = await AMap.weather({ adCode });
return position;
} catch (err) {
console.error('获取位置失败:', err);
throw err;
}
}}
