|
|
@@ -1,15 +1,7 @@
|
|
|
import axios from 'axios';
|
|
|
-import { Notify } from 'quasar';
|
|
|
|
|
|
const GEOCODING_URL = 'https://maps.googleapis.com/maps/api/geocode/json';
|
|
|
|
|
|
-// ── DEBUG via notificação ─────────────────────────────────────────
|
|
|
-const dbg = (title, data = {}) => {
|
|
|
- const lines = Object.entries(data).map(([k, v]) => `${k}: ${JSON.stringify(v)}`).join('\n');
|
|
|
- Notify.create({ color: 'teal-9', textColor: 'white', position: 'top', message: `[GEO] ${title}`, caption: lines || undefined, timeout: 8000, multiLine: true });
|
|
|
-};
|
|
|
-// ─────────────────────────────────────────────────────────────────
|
|
|
-
|
|
|
const parseAddressComponents = (components) => {
|
|
|
const get = (type, nameType = 'long_name') =>
|
|
|
components.find((c) => c.types.includes(type))?.[nameType] ?? '';
|
|
|
@@ -36,11 +28,8 @@ export const useGeocodingApi = () => {
|
|
|
const apiKey = process.env.GOOGLE_MAPS_API_KEY;
|
|
|
const usandoGeocoderNativo = !!window.google?.maps?.Geocoder;
|
|
|
|
|
|
- dbg('geocodeCep', { cep: cleaned, via: usandoGeocoderNativo ? 'Geocoder nativo' : 'HTTP', apiKey: apiKey ? `${apiKey.substring(0, 8)}...` : 'UNDEFINED' });
|
|
|
-
|
|
|
if (usandoGeocoderNativo) {
|
|
|
const results = await geocodeViaGoogleMaps({ address: `${cleaned}, Brazil` });
|
|
|
- dbg('geocodeCep nativo result', { total: results.length, encontrou: results.length > 0 });
|
|
|
if (!results.length) return null;
|
|
|
const result = results[0];
|
|
|
const parsed = parseAddressComponents(result.address_components);
|
|
|
@@ -54,7 +43,6 @@ export const useGeocodingApi = () => {
|
|
|
const { data } = await axios.get(GEOCODING_URL, {
|
|
|
params: { address: `${cleaned}, Brazil`, key: apiKey },
|
|
|
});
|
|
|
- dbg('geocodeCep HTTP result', { status: data.status, total: data.results?.length ?? 0 });
|
|
|
if (data.status !== 'OK' || !data.results.length) return null;
|
|
|
const result = data.results[0];
|
|
|
const { lat, lng } = result.geometry.location;
|
|
|
@@ -65,11 +53,8 @@ export const useGeocodingApi = () => {
|
|
|
const apiKey = process.env.GOOGLE_MAPS_API_KEY;
|
|
|
const usandoGeocoderNativo = !!window.google?.maps?.Geocoder;
|
|
|
|
|
|
- dbg('reverseGeocode chamado', { lat, lng, via: usandoGeocoderNativo ? 'Geocoder nativo' : 'HTTP', apiKey: apiKey ? `${apiKey.substring(0, 8)}...` : 'UNDEFINED' });
|
|
|
-
|
|
|
if (usandoGeocoderNativo) {
|
|
|
const results = await geocodeViaGoogleMaps({ location: { lat, lng } });
|
|
|
- dbg('reverseGeocode nativo result', { total: results.length });
|
|
|
if (!results.length) return null;
|
|
|
return { lat, lng, ...parseAddressComponents(results[0].address_components) };
|
|
|
}
|
|
|
@@ -77,7 +62,6 @@ export const useGeocodingApi = () => {
|
|
|
const { data } = await axios.get(GEOCODING_URL, {
|
|
|
params: { latlng: `${lat},${lng}`, key: apiKey },
|
|
|
});
|
|
|
- dbg('reverseGeocode HTTP result', { status: data.status, total: data.results?.length ?? 0, errorMessage: data.error_message ?? null });
|
|
|
if (data.status !== 'OK' || !data.results.length) return null;
|
|
|
const result = data.results[0];
|
|
|
return { lat, lng, ...parseAddressComponents(result.address_components) };
|
|
|
@@ -89,11 +73,8 @@ export const useGeocodingApi = () => {
|
|
|
const apiKey = process.env.GOOGLE_MAPS_API_KEY;
|
|
|
const usandoGeocoderNativo = !!window.google?.maps?.Geocoder;
|
|
|
|
|
|
- dbg('geocodeFullAddress', { query, via: usandoGeocoderNativo ? 'Geocoder nativo' : 'HTTP', apiKey: apiKey ? `${apiKey.substring(0, 8)}...` : 'UNDEFINED' });
|
|
|
-
|
|
|
if (usandoGeocoderNativo) {
|
|
|
const results = await geocodeViaGoogleMaps({ address: query });
|
|
|
- dbg('geocodeFullAddress nativo result', { total: results.length });
|
|
|
if (!results.length) return null;
|
|
|
const result = results[0];
|
|
|
return {
|
|
|
@@ -106,7 +87,6 @@ export const useGeocodingApi = () => {
|
|
|
const { data } = await axios.get(GEOCODING_URL, {
|
|
|
params: { address: query, key: apiKey },
|
|
|
});
|
|
|
- dbg('geocodeFullAddress HTTP result', { status: data.status, total: data.results?.length ?? 0, errorMessage: data.error_message ?? null });
|
|
|
if (data.status !== 'OK' || !data.results.length) return null;
|
|
|
const result = data.results[0];
|
|
|
const { lat, lng } = result.geometry.location;
|