07-04-2019 16:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-04-2019 16:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

07-04-2019 18:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


07-04-2019 18:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Gondwana Software

07-04-2019 20:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-04-2019 20:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks catplace , that’s a good idea. I’ll give that a go.

