Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Settings button to get location from phonw when press

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 Answer
0 Votes
2 REPLIES 2

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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thanks catplace , that’s a good idea. I’ll give that a go.

Best Answer
0 Votes