You could use Google’s Geocoding service. See the documentation here. And here is a sample that will console.log
state coordinates (note that need a Google Maps key to make the snippet work).
Another simple way to do it is to simply use this JSON data: https://gist.github.com/meiqimichelle/7727723.
I am currently in the process of my very first project for JS. I am creating an interactive map that will display markers on each state within the US. By using Leaflet.jS, I have achieved this by coding in every state in the US. Starting in alphabetical order, I wrote the name of each state along with the coordinates.
Here is an Example of my code:
const stateInfo = [
{
state: 'Alabama',
coords: [32.806671, -86.79113],
abbreviation: 'al',
},
{
state: 'Alaska',
coords: [61.370716, 152.404419],
abbreviation: 'ak',
},
Is there a simpler way to do this, instead of adding many lines of code for each state?