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.

37 lines
922 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. calculateDistanceAddress(teacherAddress) {
  13. if (!teacherAddress ||
  14. teacherAddress.length == 0 ||
  15. !this.position ||
  16. !this.position.latitude ||
  17. !this.position.longitude) {
  18. return 0
  19. }
  20. let minDistance = 0
  21. teacherAddress.forEach(item => {
  22. let distance = calculateDistance(
  23. this.position.latitude,
  24. this.position.longitude,
  25. item.latitude,
  26. item.longitude,
  27. )
  28. minDistance = Math.min(minDistance, distance)
  29. })
  30. return minDistance
  31. }
  32. }
  33. }