Skip to content

Commit

Permalink
Kitchen Sink: Build A Location-Based App (#647)
Browse files Browse the repository at this point in the history
* feat:adding location app

* feat:cleanup
  • Loading branch information
arunavabasucom committed Oct 4, 2023
1 parent 668954b commit 87654d1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/kitchen-sink/src/examples/locationApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { block } from 'million/react';
import { useState, useEffect } from 'react';
const LocationComponent = block(() => {
const [latitude, setLatitude] = useState<number | null>(null);
const [longitude, setLongitude] = useState<number | null>(null);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(
(position) => {
const { latitude, longitude } = position.coords;
setLatitude(latitude);
setLongitude(longitude);
},
(error) => {
setError('Error getting user location');
},
);
} else {
setError('Geolocation is not available in this browser.');
}
}, []);

return (
<div>
<h1>User Location</h1>
{latitude !== null && longitude !== null ? (
<div>
<p>Latitude: {latitude}</p>
<p>Longitude: {longitude}</p>
</div>
) : (
<p>{error || 'Loading...'}</p>
)}
</div>
);
});

export default LocationComponent;

2 comments on commit 87654d1

@vercel
Copy link

@vercel vercel bot commented on 87654d1 Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sink – ./packages/kitchen-sink

million-kitchen-sink-atit.vercel.app
sink-git-main-millionjs.vercel.app
sink-millionjs.vercel.app
sink.million.dev

@vercel
Copy link

@vercel vercel bot commented on 87654d1 Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

million-kitchen-sink – ./packages/kitchen-sink

million-kitchen-sink-git-main-millionjs.vercel.app
million-kitchen-sink.vercel.app
million-kitchen-sink-millionjs.vercel.app

Please sign in to comment.