We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
import React, { useState, useEffect } from "react"; import GoogleMapReact from "google-map-react"; import { IoIosPin } from "react-icons/io";
const Marker = ({ lat, lng }: { lat: number; lng: number }) => ( );
const Map = ({ onSubmitLocation, }: { onSubmitLocation?: (location: { lat: number; lng: number }) => void; }) => { const [center, setCenter] = useState({ lat: 0, lng: 0 }); const [marker, setMarker] = useState<{ lat: number | null; lng: number | null; }>({ lat: null, lng: null });
useEffect(() => { navigator.geolocation.getCurrentPosition( (position) => { setCenter({ lat: position.coords.latitude, lng: position.coords.longitude, }); }, (error) => { console.error("Error obtaining location", error); setCenter({ lat: 0, lng: 0 }); } ); }, []);
const handleMapClick = ({ lat, lng, }: { lat: number | null; lng: number | null; }) => { setMarker({ lat, lng }); onSubmitLocation && lat && lng && onSubmitLocation({ lat, lng }); };
return ( <div style={{ height: "60vh", width: "100%" }}> <GoogleMapReact bootstrapURLKeys={{ key: "API_KEY" }} center={center} defaultZoom={11} onClick={handleMapClick} options={{ disableDefaultUI: true, zoomControl: true, draggableCursor: "pointer", }} > {marker.lat && marker.lng && ( )}
{marker.lat} {marker.lng}
export default Map;
The text was updated successfully, but these errors were encountered:
We're getting the same. The console shows deprecations since February. Did this package not get updated yet?
Sorry, something went wrong.
No branches or pull requests
import React, { useState, useEffect } from "react";
import GoogleMapReact from "google-map-react";
import { IoIosPin } from "react-icons/io";
const Marker = ({ lat, lng }: { lat: number; lng: number }) => (
);
const Map = ({
onSubmitLocation,
}: {
onSubmitLocation?: (location: { lat: number; lng: number }) => void;
}) => {
const [center, setCenter] = useState({ lat: 0, lng: 0 });
const [marker, setMarker] = useState<{
lat: number | null;
lng: number | null;
}>({ lat: null, lng: null });
useEffect(() => {
navigator.geolocation.getCurrentPosition(
(position) => {
setCenter({
lat: position.coords.latitude,
lng: position.coords.longitude,
});
},
(error) => {
console.error("Error obtaining location", error);
setCenter({ lat: 0, lng: 0 });
}
);
}, []);
const handleMapClick = ({
lat,
lng,
}: {
lat: number | null;
lng: number | null;
}) => {
setMarker({ lat, lng });
onSubmitLocation && lat && lng && onSubmitLocation({ lat, lng });
};
return (
<div style={{ height: "60vh", width: "100%" }}>
<GoogleMapReact
bootstrapURLKeys={{ key: "API_KEY" }}
center={center}
defaultZoom={11}
onClick={handleMapClick}
options={{
disableDefaultUI: true,
zoomControl: true,
draggableCursor: "pointer",
}}
>
{marker.lat && marker.lng && (
)}
{marker.lat} {marker.lng}
);
};
export default Map;
The text was updated successfully, but these errors were encountered: