2

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.

I am hoping to use something like:

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

2 Answers 2

2

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.

0
2

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:

http://papermashup.com/read-url-get-variables-withjavascript/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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