How can I enable the unique location and zoom level of a user on a web-map to be shared?

For example, if a user zooms to lat: 75, lon: 35, zoom: 8, I would like to be able for the user to share that location through a link (for example, www.mymap.com/75/35/8). As I'm using OpenLayers, I understand how to record where the lat/lon/zoom of what the user is viewing, and also how to store this in a database if necessary, but I do not have a clear idea how (or if) this argument can be shared via the browser.

My OpenLayers code is usually something of this form:

var mapCenter = new OpenLayers.LonLat(-35, 75);             
map.setCenter(mapCenter, 3);  

For example, I would like www.mymap.com/23/15/10 to work, and all other permutations of lat/lon/zoom.


Let see this permalink example from OpenLayers site. URL in this case looks like:


As you can see alongside coordinates of map center and zoom level you can transfer list of visible layers. For detailed information see source code of Permalink control.

| improve this answer | |

You would do something like www.mymap.com?lat=75&lon=35&zoom=8. Then you can either send this to some server side script, extract the variables from the URL and make map use them, or you can use client side Javascript code (I would go for window.location) and do generally the same.

| improve this answer | |

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.