Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change api key and set new one in .env #164

Open
github-actions bot opened this issue Dec 29, 2023 · 0 comments
Open

change api key and set new one in .env #164

github-actions bot opened this issue Dec 29, 2023 · 0 comments
Labels

Comments

@github-actions
Copy link

change api key and set new one in .env

https://github.com/LukaHarambasic/harambasic.de/blob/912a632d2d6ced828b1e158d6a8394317298d6a3/src/routes/(playground)/cards/[slug]/getAddress.ts#L29

export interface Address {
	line1: string;
	line2: string;
}

function getCurrentPosition(): Promise<GeolocationPosition> {
	return new Promise((resolve, reject) => {
		if (navigator.geolocation) {
			navigator.geolocation.getCurrentPosition(
				(position) => {
					resolve(position);
				},
				(error) => {
					reject(error);
				},
				{
					enableHighAccuracy: true,
					timeout: 5000,
					maximumAge: 0
				}
			);
		} else {
			reject(new Error('Geolocation is not supported by this browser.'));
		}
	});
}

async function fetchLocation(lat: number, lon: number): Promise<Address> {
	// TODO change api key and set new one in .env
	const API_KEY = 'be669b3d2f4d4c8ea1159c413ac1da78';
	try {
		const response = await fetch(
			`https://api.geoapify.com/v1/geocode/reverse?lat=${lat}&lon=${lon}&apiKey=${API_KEY}`
		);
		const data = await response.json();
		const { address_line1, address_line2 } = data.features[0].properties;
		return {
			line1: address_line1,
			line2: address_line2
		};
	} catch (error) {
		throw new Error(String(error));
	}
}

export async function getAddress(): Promise<Address> {
	const {
		coords: { latitude, longitude }
	} = await getCurrentPosition();
	return await fetchLocation(latitude, longitude);
}

193b12882ac6504ea96127b2cc845c12edbbec7a

@github-actions github-actions bot added the todo label Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants