You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
943 B

  1. import { mapState } from 'vuex'
  2. import { calculateDistance } from '@/utils/position'
  3. export default {
  4. data() {
  5. return {
  6. }
  7. },
  8. computed: {
  9. ...mapState(['position']),
  10. },
  11. methods: {
  12. calculateDistance,
  13. calculateDistanceAddress(teacherAddress) {
  14. if (!teacherAddress ||
  15. teacherAddress.length == 0 ||
  16. !this.position ||
  17. !this.position.latitude ||
  18. !this.position.longitude) {
  19. return 0
  20. }
  21. let minDistance = 0
  22. teacherAddress.forEach(item => {
  23. let distance = calculateDistance(
  24. this.position.latitude,
  25. this.position.longitude,
  26. item.latitude,
  27. item.longitude,
  28. )
  29. minDistance = Math.min(minDistance, distance)
  30. })
  31. return minDistance
  32. }
  33. }
  34. }