I have a script that queries the front browser tab and if it's an OpenStreetMap.org map URL, extracts the latitude and longitude of the map's centre. This used to be accomplished simply by sending the following Javascript to the front tab:
However, I haven't used the script in some time and this no longer works. I believe OSM was still using OpenLayers when I last used the script successfully and it's now using Leaflet? In any case, I've spent a couple of hours trying to find the map variable that I can send the Thanks in advance. asked 03 Sep '15, 19:48 Jolin Warren |
Center lat/lon and zoom level are in the URL of where ever your www.openstreetmap.org window is looking. . . Its been a while since I've looked at Javascript but I think you can access the URL within your code and then parse out the stuff you want. answered 03 Sep '15, 20:30 stf I did think about doing that, but the URL doesn't automatically update as you drag the map. One option is doing a page source dump and then searching through, as there are embedded links in the page that have updated lat/lon, but I'd rather not be screen scraping if I can avoid it. I'd prefer a cleaner solution where I query the lat/lon specifically. If it's possible!
(03 Sep '15, 20:43)
Jolin Warren
Thanks, that helped. I don't know what I was doing previously, but it turns out that the latitude, longitude, and zoom are continuously updated in the URL, and that bookmarklet uses the URL (
(04 Sep '15, 13:03)
Jolin Warren
My mistake. I don't know what I was doing before, but you are right that the lat/lon and zoom are always updated in the URL (after the hash). Thanks stf, this is the way to go. You'll see from my answer below that I used the Javascript property
(04 Sep '15, 13:04)
Jolin Warren
|
There's a bookmarklet here that does it so I'm sure that you could get some info out of that :) answered 03 Sep '15, 21:00 SomeoneElse ♦ |