File size: 680 Bytes
2d8be8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<script>
  import {
    checkPermissions,
    requestPermissions,
    getCurrentPosition
  } from '@tauri-apps/plugin-geolocation'

  export let onMessage

  async function getPosition() {
    let permissions = await checkPermissions()
    if (
      permissions.location === 'prompt' ||
      permissions.location === 'prompt-with-rationale'
    ) {
      permissions = await requestPermissions(['location'])
    }

    if (permissions.location === 'granted') {
      getCurrentPosition().then(onMessage).catch(onMessage)
    } else {
      onMessage('permission denied')
    }
  }
</script>

<button class="btn" id="cli-matches" on:click={getPosition}>
  Get Position
</button>