Like Google maps have functions like getBounds (), getNorthEast (), and getSouthWest () for finding the corners in a viewport, do OpenStreet maps have anything similar?

Question: How to get the bounding box for a center point in OpenStreet maps through Javascript API?

Is this link of some relevance here?
http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Tile_bounding_box

From that link:

class BoundingBox {
    double north;
    double south;
    double east;
    double west;   
  }
  BoundingBox tile2boundingBox(final int x, final int y, final int zoom) {
    BoundingBox bb = new BoundingBox();
    bb.north = tile2lat(y, zoom);
    bb.south = tile2lat(y + 1, zoom);
    bb.west = tile2lon(x, zoom);
    bb.east = tile2lon(x + 1, zoom);
    return bb;
  }

  static double tile2lon(int x, int z) {
     return x / Math.pow(2.0, z) * 360.0 - 180;
  }

  static double tile2lat(int y, int z) {
    double n = Math.PI - (2.0 * Math.PI * y) / Math.pow(2.0, z);
    return Math.toDegrees(Math.atan(Math.sinh(n)));
  }

In this code, what are the north east and south west coordinates?

asked 04 Oct '12, 12:24

Anisha%20Kaul's gravatar image

Anisha Kaul
293410
accept rate: 0%

closed 04 Oct '12, 14:20

SomeoneElse's gravatar image

SomeoneElse ♦
33.3k65347792

@SomeoneElse I have read the FAQ. In which way do you think this is offtopic? Can't we have an bounding box solution for openstreet maps?

(04 Oct '12, 15:13) Anisha Kaul

The reason why questions that start "Like Google maps..." get closed here is that often they refer to the use of external Javascript libraries, which are documented elsewhere - the three links below are excellent places to start.

Openstreetmap is essentially "all about the data", and you can do with it what you like whereas with Google you're presented with only one way of interacting with map data - their "API".

(and actually, it wasn't me that originally closed the question - I reopened it to add a comment to it!)

(04 Oct '12, 16:32) SomeoneElse ♦

@SomeoneElse The google maps thing was just an "example" - just to show that I made an effort. In fact I even linked a page there to ask for confirmation if I am looking in the right direction.

Is there a way that I can make it look on topic?

(04 Oct '12, 16:36) Anisha Kaul

First, I'd have a read of the links below.

Specifically, if you read the Leaflet docs page you'll see "getBounds()" mentioned pretty near the top, which does exactly what you want. I'm sure that OpenLayers offers something similar.

However, until you've read a bit of background on how the OSM slippy map works (follow the http://wiki.openstreetmap.org/wiki/Slippy_Map link from the top of the page in your question) some of the references may be a bit confusing.

(04 Oct '12, 16:52) SomeoneElse ♦

@SomeoneElse You've been helpful and thanks for that.

(04 Oct '12, 18:44) Anisha Kaul

The question has been closed for the following reason "Question is off-topic or not relevant" by SomeoneElse 04 Oct '12, 14:20


As OpenStreetMap is only a dataset it does not have those functions. You would have to look at javascript libraries for slippy maps like OpenLayers or Leaflet for that.

permanent link

answered 04 Oct '12, 12:38

Gnonthgol's gravatar image

Gnonthgol ♦
13.6k15101198
accept rate: 16%

And you might want to start looking here.

(04 Oct '12, 14:19) SomeoneElse ♦

Gnonthgol, I have found your leaflet link helpful. I am using that API now. Thanks to @SomeonElse too.

(05 Oct '12, 12:23) Anisha Kaul

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×303
×111

question asked: 04 Oct '12, 12:24

question was seen: 6,433 times

last updated: 05 Oct '12, 12:23

powered by OSQA