local-weather/app/actions.ts

14 lines
466 B
TypeScript
Raw Normal View History

2024-05-05 20:55:51 +00:00
'use server'
import { LocationType } from "@/types/types";
export async function getLocation(searchLocation: string){
const placesKey = "AIzaSyBf1ip4XogdC6XmbfDhxS_RJDOSieycJpQ";
const url = `https://maps.googleapis.com/maps/api/geocode/json?${searchLocation}&key=${placesKey}`;
const res = await fetch(url);
if (!res.ok) {
throw new Error(`There was an error fetching the data`);
}
const data = await res.json();
return data;
}