Skip to content

Commit

Permalink
Storing location coordinates in database
Browse files Browse the repository at this point in the history
  • Loading branch information
gupta-arpan committed Jun 4, 2023
1 parent 36e9d15 commit 714d455
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
34 changes: 18 additions & 16 deletions src/components/RestaurantDetailsForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@ function RestaurantDetails() {
rphone:9999999999,
lat: -73.97599050000001,
long: -73.97599050000001,
country: "",
state: "",
locality: "",
postalCode: "",
oName:"",
oEmail:"",
oPhone:9999999999,
userID:""
})

const [restaurantLocation, setRestaurantLocation] = useState({
lat: -73.97599050000001,
long: -73.97599050000001,
country: "",
state: "",
locality: "",
postalCode: ""
});
// const [restaurantLocation, setRestaurantLocation] = useState({
// lat: -73.97599050000001,
// long: -73.97599050000001,
// country: "",
// state: "",
// locality: "",
// postalCode: ""
// });

const handleSubmit = async(e)=>{
e.preventDefault()
Expand Down Expand Up @@ -109,16 +113,14 @@ function RestaurantDetails() {
</h5>
<div className="mt-3">
<RestaurantLocationSearch
restaurantLocation={restaurantLocation}
setRestaurantLocation={setRestaurantLocation}
setRestaurant={setRestaurant}
restaurant={restaurant}

/>
<div className="w-full h-80 rounded-xl border mt-3">
<Location
latitude={restaurantLocation.lat}
longitude={restaurantLocation.long}
latitude={restaurant.lat}
longitude={restaurant.long}
/>
</div>
</div>
Expand All @@ -134,28 +136,28 @@ function RestaurantDetails() {
type="text"
name="Country"
id=""
placeholder={restaurantLocation.country}
placeholder={restaurant.country}
/>
<input
className="border rounded-lg p-2 w-5/12"
type="text"
name="pincode"
id=""
placeholder={restaurantLocation.postalCode}
placeholder={restaurant.postalCode}
/>
<input
className="border rounded-lg p-2 w-5/12"
type="text"
name="City"
id=""
placeholder={restaurantLocation.locality}
placeholder={restaurant.locality}
/>
<input
className="border rounded-lg p-2 w-5/12"
type="text"
name="State"
id=""
placeholder={restaurantLocation.state}
placeholder={restaurant.state}
/>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/components/RestaurantLocationSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function RestaurantLocationSearch(props) {
const place = inputRef.current.getPlace();
if (place) {
console.log(place.formatted_address);
props.setRestaurantLocation( {
props.setRestaurant((prevLocation) => ({
...prevLocation,
lat: place.geometry.location.lat(),
lng: place.geometry.location.lng(),
country: place.address_components.find(component =>
Expand All @@ -27,7 +28,7 @@ function RestaurantLocationSearch(props) {
postalCode: place.address_components.find(component =>
component.types.includes("postal_code")
)?.long_name,
});
}));
}
};

Expand Down Expand Up @@ -65,7 +66,7 @@ function RestaurantLocationSearch(props) {
)?.long_name;

// Update the restaurant location with the postal code
props.setRestaurantLocation((prevLocation) => ({
props.setRestaurant((prevLocation) => ({
...prevLocation,
lat: userLocation.lat,
lng: userLocation.lng,
Expand Down

0 comments on commit 714d455

Please sign in to comment.