Gravity Forms, Open Street Map API, and Leaflet JS

I’m sketching this one out because it’s a fun mix of things. I’m going to use Gravity Forms to accept submissions, the Open Street Map API will convert the address into latitude/longitude, and then we’ll display the data on a Leaflet JS map. I could have done it all in Google but I was irritated by their credit card requirement. Gravity Forms I built a pretty typical form in Gravity Forms to collect some information. I used the standard address field and removed the more detailed street address pieces. That preserved privacy and made the searches more likely to work. Getting the Lat/Long from Open Street Map API What I needed to do then was pass the address variables to the Open Street Map API to get lat/long coordinates. Since I was creating a post via Gravity Forms, I could use the gform_after_submission hook to use the form information to add info to the post we just made. The function below is a bit long but it’s not fancy. It is called right after the form gets submitted. Section 1 (see code comments) gets any/all of the address information from the form and formats it in the way that the API wants. I push it into an array because using PHP’s implode function is easier than checking for the field, […]