summaryrefslogtreecommitdiff
path: root/src/lib/maps/components/PinPointMap.jsx
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-06-12 11:00:00 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-06-12 11:00:00 +0700
commite0e0729ee57d2f9b1188a0604e3cc4a51317b0ed (patch)
treea3e1e0af99f0f918d61141d7220fa3408ce303a0 /src/lib/maps/components/PinPointMap.jsx
parent337e7a189efacbe696f4512130278952977b2da2 (diff)
<hafid> fix pinpoint
Diffstat (limited to 'src/lib/maps/components/PinPointMap.jsx')
-rw-r--r--src/lib/maps/components/PinPointMap.jsx24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/lib/maps/components/PinPointMap.jsx b/src/lib/maps/components/PinPointMap.jsx
index fde1f36c..c46d838a 100644
--- a/src/lib/maps/components/PinPointMap.jsx
+++ b/src/lib/maps/components/PinPointMap.jsx
@@ -19,7 +19,7 @@ const defaultCenter = {
lng: 106.816666,
};
-const PinpointLocation = () => {
+const PinpointLocation = ({ initialLatitude, initialLongitude, initialAddress }) => {
const { isLoaded } = useJsApiLoader({
googleMapsApiKey: process.env.NEXT_PUBLIC_GOOGLE_API_KEY,
libraries: ['places'],
@@ -34,8 +34,15 @@ const PinpointLocation = () => {
setPinedMaps,
} = useMaps();
- const [tempAddress, setTempAddress] = useState('');
- const [tempPosition, setTempPosition] = useState(defaultCenter);
+ const [tempAddress, setTempAddress] = useState(initialAddress || '');
+ const [tempPosition, setTempPosition] = useState(
+ initialLatitude && initialLongitude
+ ? { lat: parseFloat(initialLatitude), lng: parseFloat(initialLongitude) }
+ : selectedPosition.lat && selectedPosition.lng
+ ? selectedPosition
+ : defaultCenter
+ );
+
const [markerIcon, setMarkerIcon] = useState(null);
const autocompleteRef = useRef(null);
@@ -47,7 +54,12 @@ const PinpointLocation = () => {
scaledSize: new window.google.maps.Size(25, 40),
});
}
- }, [isLoaded]);
+
+ // If we have initial coordinates but no address, fetch the address
+ if (initialLatitude && initialLongitude && !initialAddress) {
+ getAddress(parseFloat(initialLatitude), parseFloat(initialLongitude));
+ }
+ }, [isLoaded, initialLatitude, initialLongitude, initialAddress]);
const getAddressComponent = (components, type) => {
const component = components.find((comp) => comp.types.includes(type));
@@ -147,6 +159,8 @@ const PinpointLocation = () => {
<input
type='text'
placeholder='Cari Alamat...'
+ value={tempAddress}
+ onChange={(e) => setTempAddress(e.target.value)}
style={{ width: '100%', padding: '8px' }}
/>
</Autocomplete>
@@ -209,4 +223,4 @@ const PinpointLocation = () => {
);
};
-export default PinpointLocation;
+export default PinpointLocation; \ No newline at end of file