Skip to content

Commit 114a756

Browse files
committed
feat(iOS): The param setGeoLanguage support iOS.
1 parent 623c668 commit 114a756

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

index.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ export function setInterval(interval: number): void;
193193
* @platform ios
194194
*/
195195
export function setDistanceFilter(time: number): void;
196+
/**
197+
* 定位超时时间,最低2s
198+
* @platform ios
199+
*/
200+
export function setLocationTimeout(number: number): void;
201+
/**
202+
* 逆地理请求超时时间,最低 2s,默认为2s 注意在单次定位请求前设置。
203+
* @platform ios
204+
*/
205+
export function setReGeocodeTimeout(number: number): void;
196206
/**
197207
* 获取当前定位
198208
* 默认只获取经纬度,`iOS` 通过 {@linkcode setLocatingWithReGeocode} 设置,是否返回逆地理信息
@@ -238,7 +248,6 @@ export function setSensorEnable(sensorEnable: boolean): void;
238248
export function setWifiScan(isOnceLocation: boolean): void;
239249
/**
240250
* 设置逆地理信息的语言,目前之中中文和英文。
241-
* @platform android
242251
* @default DEFAULT
243252
*/
244253
export function setGeoLanguage(language: 'DEFAULT' | 'EN' | 'ZH'): void;

index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,24 @@ export default class AMapGeolocation {
2929
return NativeModules.RNAMapGeolocation.isStarted();
3030
}
3131
/**
32-
* 定位超时时间,最低2s
32+
* 定位超时时间,最低 2s
3333
* @param {number} number 默认设置为2s
34+
* @platform ios
3435
*/
3536
static setLocationTimeout(number = 2) {
36-
return NativeModules.RNAMapGeolocation.setLocationTimeout(number);
37+
if (Platform.OS === "ios") {
38+
return NativeModules.RNAMapGeolocation.setLocationTimeout(number);
39+
}
3740
}
3841
/**
3942
* 逆地理请求超时时间,最低2s
4043
* @param {number} number 默认设置为2s
44+
* @platform ios
4145
*/
4246
static setReGeocodeTimeout(number = 2) {
43-
return NativeModules.RNAMapGeolocation.setReGeocodeTimeout(number);
47+
if (Platform.OS === "ios") {
48+
return NativeModules.RNAMapGeolocation.setReGeocodeTimeout(number);
49+
}
4450
}
4551
/**
4652
* 坐标转换,支持将iOS自带定位 GPS/Google/MapBar/Baidu/MapABC 多种坐标系的坐标转换成高德坐标
@@ -177,13 +183,23 @@ export default class AMapGeolocation {
177183

178184
/**
179185
* 设置逆地理信息的语言,目前之中中文和英文。
180-
* @default DEFAULT
181-
* @platform android
186+
* @param {DEFAULT | EN | ZH} language
187+
* @default DEFAULT
182188
*/
183189
static setGeoLanguage(language = 'DEFAULT') {
184190
if (Platform.OS === "android") {
185191
return NativeModules.RNAMapGeolocation.setGeoLanguage(language);
186192
}
193+
if (Platform.OS === "ios") {
194+
let value = 0;
195+
switch (language) {
196+
case 'DEFAULT': value = 0; break;
197+
case 'ZH': value = 1; break;
198+
case 'EN': value = 2; break;
199+
default: break;
200+
}
201+
return NativeModules.RNAMapGeolocation.setGeoLanguage(value);
202+
}
187203
}
188204

189205
/**

ios/RNAMapGeolocation.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ - (instancetype)init {
115115
[_manager setLocatingWithReGeocode: value];
116116
}
117117

118+
// 逆地址语言类型,默认是AMapLocationRegionLanguageDefault
119+
// AMapLocationReGeocodeLanguageDefault = 0, ///<默认,根据地区选择语言
120+
// AMapLocationReGeocodeLanguageChinse = 1, ///<中文
121+
// AMapLocationReGeocodeLanguageEnglish = 2, ///<英文
122+
RCT_EXPORT_METHOD(setGeoLanguage : (int)value) {
123+
_manager.reGeocodeLanguage = (AMapLocationReGeocodeLanguage)value;
124+
}
125+
118126
/**
119127
* @brief 转换目标经纬度为高德坐标系,不在枚举范围内的经纬度将直接返回。
120128
* @param coordinate 待转换的经纬度

0 commit comments

Comments
 (0)