Matt-Dionis / gatsby-source-googlemaps-geocoding

A Gatsby source plugin to load resources from the Google Maps Geocoding API.
0 stars 0 forks source link

How to change the location at runtime? #1

Open Shackless opened 5 years ago

Shackless commented 5 years ago

I am new to Gatsby and to the JAM stack so that might be a stupid question but (how) can I change the address to search for at run-time? I build a custom GoogleMapComponent in React that I can add to my posts in Markdown. Now I'd like to pass the address (like "Boston, CA") from my .md file like this:

// my-blog-post-123.md: 

** Regular Markdown. Here comes my custom map:  **

<map location="boston, ca"></map>

The map component expects lat and lng coordinates internally, so here comes the geocoding into play and I need to get the coordinates for the given address.

Is this possible or do I need to call the Google Geocoding API directly from my map component using axios etc.?

Matt-Dionis commented 5 years ago

Gatsby is a static site generator so there, unfortunately, is no way to tweak anything at runtime. Any variables, like location, need to be set at build time. Your use case seems to be dynamic and Gatsby may not be the best resource for it, unfortunately.

TadjM commented 5 years ago

Im having problem setting up the plugin. I need help with the query structure

0x7An commented 4 years ago

@Shackless I needed to load the places api on a gatsby site, to use this lib react-places-autocomplete, to load the script i used the gatsby-plugin-load-script, maybe this fit for you too