hms-react-native-plugin icon indicating copy to clipboard operation
hms-react-native-plugin copied to clipboard

华为和荣耀手机requestLocationUpdatesWithCallback报错'{"errorCode":800,"errorMessage":"10101: ARGUMENTS_INVALID"}'

Open inkCrazy opened this issue 6 months ago • 4 comments

"@hmscore/react-native-hms-location": "^6.12.0-302", "react": "18.2.0", "react-native": "0.72.4",

if (Platform.OS === 'android') {
    const locationRequest = {
      priority: HMSLocation.FusedLocation.Native.PriorityConstants.PRIORITY_HIGH_ACCURACY,
      interval: 3,
      numUpdates: 10,
      fastestInterval: 1000.0,
      expirationTime: 200000.0,
      expirationTimeDuration: 200000.0,
      smallestDisplacement: 0.0,
      maxWaitTime: 2000000.0,
      needAddress: false,
      // coordinateType: HMSLocation.Geofence.Native.GeofenceRequestConstants.COORDINATE_TYPE_GCJ_02,
    };
    const locationSettingsRequest = {
      locationRequests: [locationRequest],
      alwaysShow: false, //alwaysShow 属性指示应用程序是否需要某个位置才能继续
      needBle: false, //needBle 属性指示是否需要启用 BLE 扫描
    };

    const reqCode = 1;
    HMSLocation.FusedLocation.Native.requestLocationUpdatesWithCallback(locationRequest)
      .then(res => {
        console.log('requestLocationUpdatesWithCallback', res);
        HMSLocation.FusedLocation.Native.getLastLocation()
          .then(pos => {
            console.log('Last location:', pos);
            const coords = pos;

            // Transform coordinates
            const result = gcoord.transform(
              [coords.longitude, coords.latitude],
              gcoord.WGS84, // Source coordinate system
              targetCoordSystem, // Target coordinate system
            );
            console.log('Transformed Location:', result);

            const transformedLocation = {
              ...coords,
              longitude: result[0],
              latitude: result[1],
              originalCoords: coords,
              coordSystem: targetCoordSystem,
            };

            console.log('Transformed Location:', transformedLocation);

            // Call success callback with transformed location
            onSuccess && onSuccess(transformedLocation);
          })
          .catch(error => {
            Alert.alert('定位失败', error.message || '无法获取当前位置', [{text: '确定'}]);
            onError && onError(error);
            console.log('Failed to get last location', error);
          });
      })
      .catch(err => {
        //{"errorCode":800,"errorMessage":"10101: ARGUMENTS_INVALID"} //参数无效
        console.log('requestLocationUpdatesWithCallback error:', err.message);
      });
  }

inkCrazy avatar May 07 '25 02:05 inkCrazy