Open Street Map API - Changing the lat long coords

Hi all, i’ve decided to transfer my walking routes website from Multimap to openstreetmap as i’m a big believer in this sort of free information, but have run into a brick wall.:o

I’ve got the follwing code running:

Here’s my working example :

I’ve managed to hack the code so it now downloads a gpx file of the same name as the main page, but i just can’t get the lat long coord for the map to change!

The sample code suggests “// Start position for the map (hardcoded here for simplicity, but maybe you want to get from URL params)” which makes me think it’s a simple matter? It’s just not practical to change the lat long for each walk (there’s nearly a 100 there) as i’d need to work that out manually for each walk and edit something in an area that’s not editable.

Code in question is simply:
var lat=51.508
var lon=-0.118

I’m sure there’s a way to get the first waypoint from the GPX into a variable and just put it in this bit of code!

Any advice gratefully recevied! :smiley:

Once you’ve loaded the track into OL you will probably have a ‘vector feature’ which has a ‘linestring geometry’ representing the gpx track. You can then request the bounds of the geometry and use that to set the zoomlevel and center point of the map.


map.zoomToExtent(gpxfeature.geometry.getBounds(), false);

Thanks for that, but i’m not able to get it to work.
I’ve tried different combinations (inserting the above into various places in the code) , but i’m sure i’m either putting it in the wrong place, or putting the wrong text in place of gpxfeature.

I’m sure there’s a way to put the code above as var lat = …code…, i’ll keep trying!

on a side note, you confused the openstreetmap api with openlayers. Openlayers is a different project and has not much to do with OSM, other then massive use of the OL api by the OSM community. Have you tried the openlayers irc channel?
With this post i do not mean though, you are wrong here with these questions, just helping you to find an answer.

I know that OL is very powerful but as a result also has a very steep learning curve. Unfortunately it’s documentation isn’t the best for beginners, so here are a few pointers:

  • Get Firefox and the firebug plugin.
  • Study the OL examples.
  • Study the DOM in Firefox using the firebug plugin.
  • Copy paste interesting examples and try to expand them to do what you want.

SORRY. This post one should have gone elsewhere. I’ll move it there.

I started doing map edits in my neighborhood, but I have a doubt/question about the unimproved roadways. I did read the suggestions in the Map Features section of wiki, but they don’t answer my question. The question is: how to mark unimproved residential roads (within city limits). There are quite a few in my neighborhood and some of them could be bad to get into after dark. They are not service roads, but on the other the highway=tracks is recommended for agricultural use and forests.

You site looks really cool, I wish I had that view from my bedroom.

Openstreetmp data browser does this:

        for (var i = 1; i < this.features.length; i++) {

        if (extent) {
        } else {

That seems to me what you would like to use, might not work but… :slight_smile: