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.

41 lines
1006 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, index) => {
  23. let distance = calculateDistance(
  24. this.position.latitude,
  25. this.position.longitude,
  26. item.latitude,
  27. item.longitude,
  28. )
  29. if(index == 0){
  30. minDistance = distance
  31. }
  32. minDistance = Math.min(minDistance, distance)
  33. })
  34. return minDistance
  35. }
  36. }
  37. }