From 776d26572e69fa9d0b57b586262e4bd86b21dd92 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 8 Sep 2025 15:04:49 +0700
Subject: <hafid> validation Address

---
 src/lib/maps/components/PinPointMap.jsx | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

(limited to 'src/lib/maps/components/PinPointMap.jsx')

diff --git a/src/lib/maps/components/PinPointMap.jsx b/src/lib/maps/components/PinPointMap.jsx
index 75ab1d59..753f65c7 100644
--- a/src/lib/maps/components/PinPointMap.jsx
+++ b/src/lib/maps/components/PinPointMap.jsx
@@ -33,6 +33,8 @@ const PinpointLocation = ({
     getDefaultCenter, // ✅ ambil default center dari store
   } = useMaps();
 
+
+
   const [tempAddress, setTempAddress] = useState(initialAddress || '');
   const [tempPosition, setTempPosition] = useState(
     initialLatitude && initialLongitude
@@ -42,6 +44,23 @@ const PinpointLocation = ({
       : getDefaultCenter() // ✅ fallback aman untuk view
   );
 
+  useEffect(() => {
+    if (initialLatitude && initialLongitude) {
+      const lat = parseFloat(initialLatitude);
+      const lng = parseFloat(initialLongitude);
+
+      if (!isNaN(lat) && !isNaN(lng)) {
+        setTempPosition({ lat, lng });
+        // kalau address belum ada, reverse geocode
+        if (!initialAddress) {
+          getAddress(lat, lng);
+        } else {
+          setTempAddress(initialAddress);
+        }
+      }
+    }
+  }, [initialLatitude, initialLongitude, initialAddress]);
+
   const [markerIcon, setMarkerIcon] = useState(null);
   const autocompleteRef = useRef(null);
 
@@ -68,7 +87,7 @@ const PinpointLocation = ({
   const getAddress = async (lat, lng) => {
     try {
       const response = await fetch(
-        `https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&key=${process.env.NEXT_PUBLIC_GOOGLE_API_KEY}`
+        `https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&key=${process.env.NEXT_PUBLIC_GOOGLE_API_KEY}&language=id`
       );
       const data = await response.json();
 
-- 
cgit v1.2.3

