Skip to content

Instantly share code, notes, and snippets.

@achingachris
Last active April 22, 2022 13:20
Show Gist options
  • Save achingachris/d602a18f74808e25247cc34545a18433 to your computer and use it in GitHub Desktop.
Save achingachris/d602a18f74808e25247cc34545a18433 to your computer and use it in GitHub Desktop.
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='&copy; <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