Getting Latitude and Longitude from an OpenStreetMap Map

Using leaflet.js and Open Street Maps
By Allen Edwards


Filling a form with the results of a map click on an openstreetmap seems straight forward. I tried half a dozen examples online and none worked. None just presented working code. They all gave html, css, and js and after carefully putting them together they did not work. Some worked but did not fill out a form or enable the location to be used off the map. This demo works and I give the source code and a working single php page. The app uses leaflet and Open Street Map maps. All this is free and open source. This "Article" is really a demo. Just click on the map. The location will be filled in both in text areas and in the form.

This code is used in the new feature that allows you to select two locations for the 7 day forecast graphs in the Weather & Tide app. You should check that out. Click EDIT in the 7 Day Forecast section. Even if you are not a developer, I thought you might fine interesting what goes into making this site work even better.

The Demo

location is 37.818,-122.478

Click on map and then select ENTER.


View stand alone

NOTICE: Some pages have affiliate links to Amazon. As an Amazon Associate, I earn from qualifying purchases. Please read website Cookie, Privacy, and Disclamers by clicking HERE. To contact me click HERE. For my YouTube page click HERE