2
votes

i'm follwing @hmscore/react-native-hms-location documontation with react native, i'm trying to Continuously Obtaining the Location Information with the requestLocationUpdatesWithCallback() and addFusedLocationEventListener() functions i can get the request code from requestLocationUpdatesWithCallback() but the addFusedLocationEventListener() returns nothing , like it dosen't trigered

 HMSLocation.FusedLocation.Native.requestLocationUpdatesWithCallbackEx(locationRequest)
  .then((res) => console.log(res))
  .catch((err) => alert(err.message))
  

////////////////////////

HMSLocation.FusedLocation.Events.addFusedLocationEventListener(handleLocationUpdate)


 /////////////////////


const handleLocationUpdate = (locationResult) => console.log(locationResult)

any solution for that

2

2 Answers

1
votes

The location duration depends on the locationRequest configuration.

The parameter settings provided in the Demo do not support continuously obtaining the Location Information. You are advised to configure the parameters as follows:

    const locationRequest = {
      priority: HMSLocation.FusedLocation.Native.PriorityConstants.PRIORITY_HIGH_ACCURACY,
      interval: 60000,    
      numUpdates: 2147483647, 
      fastestInterval: 30000.0,  
      expirationTimeDuration: 2147483647, 
      smallestDisplacement: 0.0,
      language: 'en',
      countryCode: 'en',
    };

For details about the parameters, see Docs.

0
votes

From what it seems, this should work. However, there may be permissions you are missing. Please use requestPermission() and hasPermission() functions to request and check if you do indeed have the necessary permissions to actually receive any location information.

You may also want to make a mock location with setMockMode and setMockLocation to make sure your program is working as expected.

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-References-V1/fusedlocation-0000001050043303-V1#EN-US_TOPIC_0000001050140366__section1060819319425