Address.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <div>
  3. <v-text-field
  4. v-model="text"
  5. type="text"
  6. name="search-city"
  7. class="search-bar"
  8. outlined
  9. :label="$t('where') + ' ?'"
  10. autocomplete="off"
  11. append-icon="mdi-crosshairs-gps"
  12. @change="$emit('change', $event)"
  13. @click:append="geolocalizeUser"
  14. />
  15. <v-snackbar :value="errorMsg !== ''">
  16. {{ errorMsg }}
  17. <template #action="{ attrs }">
  18. <v-btn text v-bind="attrs" @click="errorMsg=''">
  19. {{ $t('close') }}
  20. </v-btn>
  21. </template>
  22. </v-snackbar>
  23. </div>
  24. </template>
  25. <script>
  26. export default {
  27. data () {
  28. return {
  29. latitude: null,
  30. longitude: null,
  31. text: '',
  32. errorMsg: ''
  33. }
  34. },
  35. methods: {
  36. geolocalizeUser () {
  37. if (navigator.geolocation) {
  38. navigator.geolocation.getCurrentPosition(
  39. (position) => {
  40. this.latitude = position.coords.latitude
  41. this.latitude = position.coords.longitude
  42. this.text = this.$t('my_position')
  43. },
  44. () => {
  45. this.errorMsg = this.$t('geolocation_error')
  46. }
  47. )
  48. } else {
  49. this.errorMsg = this.$t('geolocation_not_supported')
  50. }
  51. }
  52. }
  53. }
  54. </script>
  55. <style>
  56. .v-input__control {
  57. height: 56px;
  58. }
  59. </style>