Is there a way to set the xy and zoom level of a map using the URL of the site that is calling it?

I'm thinking of a site I'm using now, built on php, which has mapbox maps built in javascript and added to a DIV.

Could there be a way to use something like:

http: //mysite.com/map.php?x=234.534&y=34323.2343&zoom=5

Does that make sense?



If you're using mapbox.js directly, you can call map.ui.hash.add() (assuming your map variable is named map), and the page will have a hash like #10.00/45.5342/-73.7457 which encodes the zoom level, latitude, and longitude of the map position, and you can send users to URLs like that to set the initial map position.

  • Tom - got this to work, and saw the example under 'toggle map controls'. Thank you again!!! – DPSSpatial Dec 12 '12 at 19:57

Here's a code snippet I found online that parses PHP URL variables into JavaScript. You may have to modify it a little to fit your needs, but it's pretty short and simple:


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.