07-04-2019 16:14
07-04-2019 16:14
Hi guys,
I am trying to add a button to get the user's phone location only when they press a button in the settings menu. The idea is each time the button is pressed, the current latitude and longitude is returned and is passed to the app for use in a calculation.
<Button
label="Get Phone's GPS Each Time Press"
onClick={() =>
//Trigger companion geolocation function to get phone's lat/long each time this button is pressed
//Show the latest lat / long once the geolocation is found
}
/>Thanks.
Best Answer07-04-2019 18:39
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
07-04-2019 18:39
I've never found an elegant way of getting settings code to execute companion code, or vice versa. The only way I've found is to throw settings 'over the fence'. So, in your onClick, set a setting, such as
props.settingsStorage.setItem('doGeolocation','true');Then, in your companion, detect changes in that setting (in both places!) and do what you need to do. In the companion setting handler, you should probably reset the setting to false so that it can fire again.
I think there's a geolocation function in the device API too; I assume it's unsuitable.
Best Answer07-04-2019 20:19
07-04-2019 20:19
Thanks catplace , that’s a good idea. I’ll give that a go.
Best Answer