comment actions

This commit is contained in:
christian 2024-05-08 08:53:30 +02:00
parent e3f0a72539
commit e98edf431d

View File

@ -1,5 +1,4 @@
'use server' 'use server'
import { Forecast, LocationType, coordType } from "@/types/types"; import { Forecast, LocationType, coordType } from "@/types/types";
//takes address and returns coords in obj as {lat: number, lng: number} //takes address and returns coords in obj as {lat: number, lng: number}
@ -14,9 +13,10 @@ export async function getLocation(searchLocation: string): Promise<coordType>{
return data.results[0].geometry.location; return data.results[0].geometry.location;
} }
// takes coordinates in coordType format and returns json with weather forecast.
export async function getForecast(geoLocation: coordType): Promise<Forecast> { export async function getForecast(geoLocation: coordType): Promise<Forecast> {
const { lat, lng } = geoLocation; const { lat, lng } = geoLocation;
const appId = "546911d860cb81f16585f7973b394b70"; const appId = '546911d860cb81f16585f7973b394b70';
const res = await fetch( const res = await fetch(
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lng}&appid=${appId}` `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lng}&appid=${appId}`
); );