Commit 4d38fa7fe508ee8f8065999bec62256069eb0071

Authored by 张志伟
1 parent 174369d5

🔥 feat(*): 添加额外定位数据

lib/android/build.gradle
... ... @@ -32,6 +32,6 @@ android {
32 32 dependencies {
33 33 implementation 'com.facebook.react:react-native:+'
34 34 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getExt('kotlinVersion', '1.6.21')}"
35   - implementation 'com.amap.api:3dmap:9.5.0'
36   - implementation 'com.amap.api:search:9.4.5'
  35 + implementation 'com.amap.api:3dmap:9.8.2'
  36 + implementation 'com.amap.api:search:9.7.0'
37 37 }
... ...
lib/android/src/main/java/cn/feewee/amap3d/modules/AMapGeolocationModule.java
... ... @@ -30,7 +30,7 @@ import java.util.ArrayList;
30 30 @SuppressWarnings("unused")
31 31 public class AMapGeolocationModule extends ReactContextBaseJavaModule implements AMapLocationListener {
32 32 private final ReactApplicationContext reactContext;
33   - private final AMapLocationClientOption option = new AMapLocationClientOption();
  33 + private final AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
34 34 private DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter;
35 35 private AMapLocationClient client;
36 36 private GeocodeSearch geocodeSearch;
... ... @@ -65,17 +65,22 @@ public class AMapGeolocationModule extends ReactContextBaseJavaModule implements
65 65 AMapLocationClient.setApiKey(key);
66 66 AMapLocationClient.updatePrivacyShow(reactContext, true, true);
67 67 AMapLocationClient.updatePrivacyAgree(reactContext, true);
68   - ServiceSettings.updatePrivacyShow(reactContext,true,true);
69   - ServiceSettings.updatePrivacyAgree(reactContext,true);
  68 + ServiceSettings.updatePrivacyShow(reactContext, true, true);
  69 + ServiceSettings.updatePrivacyAgree(reactContext, true);
70 70 client = new AMapLocationClient(reactContext);
71 71 geocodeSearch = new GeocodeSearch(reactContext);
72 72 client.setLocationListener(this);
  73 + mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
  74 + mLocationOption.setMockEnable(false);
  75 + mLocationOption.setLocationCacheEnable(false);
  76 + client.setLocationOption(mLocationOption);
73 77 eventEmitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
74 78 promise.resolve(null);
75 79 }
76 80  
77 81 @ReactMethod
78 82 public void start() {
  83 + client.stopLocation();
79 84 client.startLocation();
80 85 }
81 86  
... ... @@ -104,95 +109,95 @@ public class AMapGeolocationModule extends ReactContextBaseJavaModule implements
104 109  
105 110 @ReactMethod
106 111 public void setOnceLocation(boolean value) {
107   - option.setOnceLocation(value);
108   - client.setLocationOption(option);
  112 + mLocationOption.setOnceLocation(value);
  113 + client.setLocationOption(mLocationOption);
109 114 }
110 115  
111 116 @ReactMethod
112 117 public void setWifiScan(boolean value) {
113   - option.setWifiScan(value);
114   - client.setLocationOption(option);
  118 + mLocationOption.setWifiScan(value);
  119 + client.setLocationOption(mLocationOption);
115 120 }
116 121  
117 122 @ReactMethod
118 123 public void setInterval(int interval) {
119   - option.setInterval(interval);
120   - client.setLocationOption(option);
  124 + mLocationOption.setInterval(interval);
  125 + client.setLocationOption(mLocationOption);
121 126 }
122 127  
123 128 @ReactMethod
124 129 public void setSensorEnable(boolean value) {
125   - option.setSensorEnable(value);
126   - client.setLocationOption(option);
  130 + mLocationOption.setSensorEnable(value);
  131 + client.setLocationOption(mLocationOption);
127 132 }
128 133  
129 134 @ReactMethod
130 135 public void setOpenAlwaysScanWifi(boolean value) {
131 136 AMapLocationClientOption.setOpenAlwaysScanWifi(value);
132   - client.setLocationOption(option);
  137 + client.setLocationOption(mLocationOption);
133 138 }
134 139  
135 140 @ReactMethod
136 141 public void setNeedAddress(boolean value) {
137   - option.setNeedAddress(value);
138   - client.setLocationOption(option);
  142 + mLocationOption.setNeedAddress(value);
  143 + client.setLocationOption(mLocationOption);
139 144 }
140 145  
141 146 @ReactMethod
142 147 public void setOnceLocationLatest(boolean value) {
143   - option.setOnceLocationLatest(value);
144   - client.setLocationOption(option);
  148 + mLocationOption.setOnceLocationLatest(value);
  149 + client.setLocationOption(mLocationOption);
145 150 }
146 151  
147 152 @ReactMethod
148 153 public void setMockEnable(boolean value) {
149   - option.setMockEnable(value);
150   - client.setLocationOption(option);
  154 + mLocationOption.setMockEnable(value);
  155 + client.setLocationOption(mLocationOption);
151 156 }
152 157  
153 158 @ReactMethod
154 159 public void setLocationCacheEnable(boolean value) {
155   - option.setLocationCacheEnable(value);
156   - client.setLocationOption(option);
  160 + mLocationOption.setLocationCacheEnable(value);
  161 + client.setLocationOption(mLocationOption);
157 162 }
158 163  
159 164 @ReactMethod
160 165 public void setGpsFirst(boolean value) {
161   - option.setGpsFirst(value);
162   - client.setLocationOption(option);
  166 + mLocationOption.setGpsFirst(value);
  167 + client.setLocationOption(mLocationOption);
163 168 }
164 169  
165 170 @ReactMethod
166 171 public void setHttpTimeout(int value) {
167   - option.setHttpTimeOut(value);
168   - client.setLocationOption(option);
  172 + mLocationOption.setHttpTimeOut(value);
  173 + client.setLocationOption(mLocationOption);
169 174 }
170 175  
171 176 @ReactMethod
172 177 public void setGpsFirstTimeout(int value) {
173   - option.setGpsFirstTimeout(value);
174   - client.setLocationOption(option);
  178 + mLocationOption.setGpsFirstTimeout(value);
  179 + client.setLocationOption(mLocationOption);
175 180 }
176 181  
177 182 @ReactMethod
178 183 public void setLocationMode(String mode) {
179   - option.setLocationMode(AMapLocationClientOption.AMapLocationMode.valueOf(mode));
180   - client.setLocationOption(option);
  184 + mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.valueOf(mode));
  185 + client.setLocationOption(mLocationOption);
181 186 }
182 187  
183 188 @ReactMethod
184 189 public void setLocationPurpose(String purpose) {
185   - option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.valueOf(purpose));
186   - client.setLocationOption(option);
  190 + mLocationOption.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.valueOf(purpose));
  191 + client.setLocationOption(mLocationOption);
187 192 }
188 193  
189 194 @ReactMethod
190 195 public void setGeoLanguage(String language) {
191   - option.setGeoLanguage(AMapLocationClientOption.GeoLanguage.valueOf(language));
192   - client.setLocationOption(option);
  196 + mLocationOption.setGeoLanguage(AMapLocationClientOption.GeoLanguage.valueOf(language));
  197 + client.setLocationOption(mLocationOption);
193 198 }
194 199  
195   - @ReactMethod
  200 + @ReactMethod
196 201 public void reverseGeoCode(double lat, double lng, Float radius, Promise promise) {
197 202 if (lat <= 0 || lng <= 0) {
198 203 promise.reject(String.valueOf(-2), "无效的经纬度");
... ... @@ -289,6 +294,8 @@ public class AMapGeolocationModule extends ReactContextBaseJavaModule implements
289 294 WritableMap map = Arguments.createMap();
290 295 map.putInt("errorCode", location.getErrorCode());
291 296 map.putString("errorInfo", location.getErrorInfo());
  297 + map.putString("deviceId", AMapLocationClient.getDeviceId(reactContext));
  298 + map.putString("sdkVersion", client.getVersion());
292 299 map.putString("locationDetail", location.getLocationDetail());
293 300 if (location.getErrorCode() == AMapLocation.LOCATION_SUCCESS) {
294 301 map.putDouble("timestamp", location.getTime());
... ... @@ -302,6 +309,10 @@ public class AMapGeolocationModule extends ReactContextBaseJavaModule implements
302 309 map.putString("coordinateType", location.getCoordType());
303 310 map.putInt("gpsAccuracy", location.getGpsAccuracyStatus());
304 311 map.putInt("trustedLevel", location.getTrustedLevel());
  312 + map.putString("aoiName", location.getAoiName());
  313 + map.putString("buildingId", location.getBuildingId());
  314 + map.putString("floor", location.getFloor());
  315 +
305 316 if (!location.getAddress().isEmpty()) {
306 317 map.putString("address", location.getAddress());
307 318 map.putString("description", location.getDescription());
... ...
lib/src/amap-geolocation.ts
... ... @@ -77,6 +77,22 @@ export function setOnceLocation(isOnceLocation: boolean) {
77 77 }
78 78 }
79 79  
  80 +
  81 +/**
  82 + * 获取最近3s内精度最高的一次定位结果
  83 + *
  84 + * 定位精度会更高,但是定位速度会变慢 1-3 秒,
  85 + * 当设置为 `true` 时,连续定位会自动变为单次定位。
  86 + *
  87 + * @default false
  88 + * @platform android
  89 + */
  90 +export function setOnceLocationLatest(isOnceLocationLatest: boolean) {
  91 + if (Platform.OS === "android") {
  92 + AMapGeolocation.setOnceLocationLatest(isOnceLocationLatest);
  93 + }
  94 +}
  95 +
80 96 /**
81 97 * 设置是否允许调用 WiFi 刷新
82 98 *
... ... @@ -121,21 +137,6 @@ export function setOpenAlwaysScanWifi(isOpen: boolean) {
121 137 }
122 138  
123 139 /**
124   - * 设置定位是否等待 WiFi 列表刷新
125   - *
126   - * 定位精度会更高,但是定位速度会变慢 1-3 秒,
127   - * 当设置为 `true` 时,连续定位会自动变为单次定位。
128   - *
129   - * @default false
130   - * @platform android
131   - */
132   -export function setOnceLocationLatest(isOnceLocationLatest: boolean) {
133   - if (Platform.OS === "android") {
134   - AMapGeolocation.setOnceLocationLatest(isOnceLocationLatest);
135   - }
136   -}
137   -
138   -/**
139 140 * 设置是否返回地址信息,默认返回地址信息
140 141 *
141 142 * GPS 定位时也可以返回地址信息,但需要网络通畅,第一次有可能没有地址信息返回。
... ... @@ -152,7 +153,7 @@ export function setNeedAddress(isNeedAddress: boolean) {
152 153 /**
153 154 * 设置是否允许模拟位置
154 155 *
155   - * @default true
  156 + * @default false
156 157 * @platform android
157 158 */
158 159 export function setMockEnable(enable: boolean) {
... ... @@ -164,7 +165,7 @@ export function setMockEnable(enable: boolean) {
164 165 /**
165 166 * 设置是否使用缓存策略
166 167 *
167   - * @default true
  168 + * @default false
168 169 * @platform android
169 170 */
170 171 export function setLocationCacheEnable(enable: boolean) {
... ... @@ -216,7 +217,8 @@ export function setGpsFirst(isGpsFirst: boolean) {
216 217  
217 218 /**
218 219 * 设置定位模式
219   - *
  220 + *
  221 + * @default LocationMode.Hight_Accuracy
220 222 * @platform android
221 223 */
222 224 export function setLocationMode(mode: LocationMode) {
... ...
lib/src/gen-types.ts
... ... @@ -345,6 +345,18 @@ export interface ILocation {
345 345 * @platform android
346 346 */
347 347 trustedLevel?: TrustedLevel;
  348 + /**
  349 + * 当前定位点的AOI信息
  350 + */
  351 + aoiName?: string;
  352 + /**
  353 + * 当前室内定位的建筑物Id
  354 + */
  355 + buildingId?: string;
  356 + /**
  357 + * 当前室内定位的楼层
  358 + */
  359 + floor?: string;
348 360 }
349 361  
350 362 /**
... ...
package.json
1 1 {
2 2 "name": "@cqfw/react-native-amap3d",
3   - "version": "0.3.0",
  3 + "version": "0.3.1",
4 4 "description": "react-native 高德地图组件,支持 Android + iOS",
5 5 "author": "feewee",
6 6 "license": "MIT",
... ...