Last active
April 22, 2022 13:20
-
-
Save achingachris/d602a18f74808e25247cc34545a18433 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useRef } from 'react' | |
import { MapContainer, TileLayer, Marker } from 'react-leaflet' | |
import 'leaflet/dist/leaflet.css' | |
const OpenStreetMap = () => { | |
const [center, setCenter] = useState({ lat: -4.043477, lng: 39.668205 }) | |
const ZOOM_LEVEL = 9 | |
const mapRef = useRef() | |
return ( | |
<> | |
<div className='container'> | |
<div className='container'> | |
<h1 className='text-center-mt-5'>OpenStreetMap Embeded</h1> | |
</div> | |
<div className='row'> | |
<div className='col'> | |
<div className='container'> | |
<MapContainer center={center} zoom={ZOOM_LEVEL} ref={mapRef}> | |
<TileLayer | |
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | |
url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' | |
/> | |
{location.loaded && !location.error && ( | |
<Marker | |
position={[ | |
location.coordinates.lat, | |
location.coordinates.lng, | |
]} | |
></Marker> | |
)} | |
</MapContainer> | |
</div> | |
</div> | |
</div> | |
</div> | |
</> | |
) | |
} | |
export default OpenStreetMap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment