I am new to web mapping and am looking out for a solution to my issue. I have been working on creating a Web Map for Paying guest location from my workplace and am looking to find the distance to each PG locations. However I am not sure how to do this? Can anybody help?

I am using GeoServer, Postgresql and Leaflet. To do the query is there any plugins available or do I have to write a Javascript code?


There is a whole slew of measurement plugins available for Leaflet. Leaflet-MeasureControl and leaflet_measure both appear to have potential for your use-case. Alternatively, it would be very simple to implement your own point to point measurement using trigonometry. If the distances are short (10s of km), then you would not need the Haversine formula (though that too is an option for greater accuracy - do a search on this site for more info).

I also notice that you are using Postgresql and Geoserver. Yet another option is for you send the coordinates back to either Postgresql (through your web-server backend) or, even easier still, to Geoserver as a REST request and write a simple SQL query that will return the distance using ST_Distance. This would be a lot simpler than trying to implement the Haversine formula (so long as you remember to cast your coordinates as Geography types). Geoserver would then return the distance as JSON.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.