how can i get leaflet.js to map longitude, latitude rather than latititude, longitude
- User
how can i get leaflet.js to map longitude, latitude rather than latititude, longitude
- Assistant
To configure Leaflet.js to map longitude, latitude instead of latitude, longitude, you can use the
setLatLngmethod instead ofsetViewto set the initial center of the map.Here's an example:
<!DOCTYPE html> <html> <head> <title>Leaflet.js Map</title> <link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet/dist/leaflet.css"> <style> #map { height: 400px; } </style> </head> <body> <div id="map"></div> <script src="https://unpkg.com/leaflet/dist/leaflet.js"></script> <script> // Create a map centered on longitude, latitude var map = L.map('map').setView([-122.4194, 37.7749], 13); // Add a tile layer for the map background L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' }).addTo(map); // Add a marker at longitude, latitude L.marker([-122.4194, 37.7749]).addTo(map); </script> </body> </html>