NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

So what i'm trying to do is a web-application to calculate routes between two coordinates. I've set up a map with leafletjs with the first tile server in the list on this page. I set up a function which returns the coordinates where I click on the map. The thing, that is irritating to me, is that the coordinates that my map returns are not the same as other web-maps return (for example openrouteservice-map) for the exact same position. Here's an example:

These are the coordinates from my map: 85327.45845973487,46.94840207976996 (long, lat). These are the coordinates from the openrouteservice-map: 7.457968, 46.948518 (long, lat) for the exact same position.

The longitude value is very different between the two.

So my question is, why are the coordinates that my map returns, different than what other maps return? And also, if I use the coordinates of my map for the route calculation, they don't work.

I have aready tried changing the CRS (Coordinate Reference System), but that didn't do a difference.

Any help or hint is very appreciated, thank you.

asked 29 Nov '21, 10:47

nicolabaechi's gravatar image

nicolabaechi
56114
accept rate: 0%

2

Add a link to your (dev) site where we can check what you are doing. Sth. is either wrong here: "I set up a function which returns the coordinates where I click on the map" or you just scrolled "endlessly" to the right before clicking on the map and by that got that crazy long coordinate. You may also set a bounding box for your map in leaflet to disable the option of endless scrolling in any direction, so your long will be between -180 and 180 (and lat between -90 and 90).

(29 Nov '21, 14:39) Spiekerooger

Hey, I set up this codesandbox. Don't know if it works in the environment, maybe pull it locally. Yes what you said could be, but what would cause this behaviour?

(29 Nov '21, 15:27) nicolabaechi

I managed to solve my issue by setting a boundingbox as @Spiekerooger suggested, thank you :).

I did that like this:

// setting the corners of the bounding box var corner1 = L.latLng(47.86108855623179, 5.883178710937501); var corner2 = L.latLng(45.77901739936284, 10.5743408203125); var bounds = L.latLngBounds(corner1, corner2); // adding it as a property to the map this.map = L.map('map', { ..., maxBounds: bounds, });

permanent link

answered 30 Nov '21, 10:27

nicolabaechi's gravatar image

nicolabaechi
56114
accept rate: 0%

Your answer
toggle preview

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:

×305
×74
×5
×2

question asked: 29 Nov '21, 10:47

question was seen: 1,668 times

last updated: 30 Nov '21, 10:27

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum