import { ref } from 'vue';


export const useLocation = () => {
  const location = ref<UniApp.GetLocationSuccess>();

  const getLocation = async() => {
    const res = await uni.getLocation({ isHighAccuracy: true, type: 'gcj02' });
    if (!res?.latitude || !res?.longitude) {
      throw new Error();
    }
    location.value = res;
  };

  return {
    location,
    getLocation,
  };
};
