npm installto install dependencies.- You'll need a Google Maps API key - get one here and set up your
.envfile, using.env.exampleas a guide. npm run devto start the development server.- Open up
localhost:8080in your browser and you should see the map! - Make some changes - various configuration options can be found in
index.jsx. Hit save, and the page will reload with your new code.
- Copy
app/components/GMap.jsxandapp/components/MapStyles.jsinto your project. npm install react-load-scriptwill install the npm package needed to load Google Maps within the component.- Replace
process.env.GOOGLE_API_KEYin therendermethod with your API key (either by setting it as a Node environment variable or by copying and pasting if you live on the edge).
<Gmap /> with no props renders a regular map with no styling or markers, centered at latitude 29.975588 and longitude -90.102682.
To customize the map, pass it a config object as a prop. Example usage:
let settings = {
{
colors: {
base: "#212121",
baseContour1: "#4d4d4d",
baseContour2: "#797979",
baseContour3: "#a6a6a6",
accent: "#fcbd40",
accentLight: "#fcb24b"
},
legend: true, // if true, you must have at least one custom icon set
icons: {
revelry: {
name: "Revelry",
image: './app/RevMarker.png',
}
},
initialCenter: {
lat: 29.975588,
lng: -90.102682
},
initialZoom: 11,
markers: [
{
position: {
lat: 29.975588,
lng: -90.102682
},
icon: 'revelry',
message: [
"<h3>Revelry Labs</h3>",
"<p>4200 Canal St, Suite E</p>",
"<p>New Orleans, LA 70119</p>"].join(""),
},
],
snapToUserLocation: false,
}
}
<GMap config={settings} />
All properties in the config object are optional, so if you don't want, say, custom colors, just remove the colors from the config object and it will render with the default Google Maps colors.