NOTICE: is being shutdown on 1st March 2024. Please use the OpenStreetMap Community Forum

Picture supposed to be hereI am currently working with map data from Nairobi,Kenya. I am using leaflet to place textboxes on places clicked on the map and have their coordinates returned. Sometimes the pattern I get suggests that the coordinates being returned are incorrect. For example, there is this instance where I clicked and created 6 textboxes. The further east I went, the smaller the longitudes were getting. From my knowledge of geography, it should be the other way round. Is this a problem with the data or could it be coming from leaflet?


My code for creating textboxes looks like this:

  var counter = 0;
  var coordinates = {};

      function onMapClick(e) {
     var order_box = '<input type="text" id= ' + '"' + counter + '"' + ' size = "5">';

     var myIcon = new L.divIcon({

     var marker = new L.marker(e.latlng, {icon: myIcon}).addTo(map);
     coordinates[counter] = e.latlng;
     str = JSON.stringify(coordinates);

     document.getElementById('coord1').value = str;

asked 26 Feb '18, 14:03

imonike's gravatar image

accept rate: 100%

edited 28 Feb '18, 22:26

aseerel4c26's gravatar image

aseerel4c26 ♦

Is this related to OSM? For more general GIS questions, try GIS StackExchange.

(26 Feb '18, 15:06) neuhausr

Yes it is.

(26 Feb '18, 15:43) imonike

Can you give an example - for example give a URL in OSM (like , but zoomed in much more) where the you have clicked on a map and got co-ordinates that you didn't expect?

(26 Feb '18, 15:47) SomeoneElse ♦

I have a screen-shot that clearly shows the issue. Is there a way for attaching files?

(26 Feb '18, 15:56) imonike

You could upload a picture to an image host and link to that - I've used for that, but plenty of others are available.

(26 Feb '18, 17:24) SomeoneElse ♦

Thanks @SomeoneElse. @andy-mackey has told me what to do. The screen-shot should be visible now.

(27 Feb '18, 10:16) imonike

What is that a screen shot of? It's clearly something running on your PC on port 5000, but what?

(27 Feb '18, 10:28) SomeoneElse ♦

@SomeoneElse. I am building a python based app using the flask framework. I make use of the leaflet library that sources its map data from OSM.

(27 Feb '18, 12:14) imonike

@SomeoneElse. I am trying to build an app that helps with deliveries, so I place textboxes at locations deliveries are to be made and place the size of the order in the textbox. I use javascript alert boxes to debug my code. In it are 6 entries for 6 orders. Each order entry contains serial number, size of order and location coordinates of order. The leaflet API provides functionality for getting the lat and lon of any point on the map clicked.

(27 Feb '18, 12:25) imonike
showing 5 of 9 show 4 more comments

Hello all. Sorry I am just getting back to this. I have been caught up attending to job-related tasks. @nevw, turns out you were right. I had a line of code with one wrong operand in a subtraction operation that causing the coordinates to be reversed and mapped to the wrong textbox. Thank you all for all the help.

permanent link

answered 05 Mar '18, 14:07

imonike's gravatar image

accept rate: 100%

I've made this ths accepted answer - hope you don't mind!

(05 Mar '18, 14:09) SomeoneElse ♦

@SomeoneElse Please, be my guest! :-) Thank you

(05 Mar '18, 14:14) imonike

BTW (didn't want to add this before to not make the confusion all too large as it was clear that you had a technical issue), the REAL answer is: YES

Lots of place coordinates in Africa have been imported from catastrophically bad data sources and are very often simply nonsense.

(05 Mar '18, 15:17) SimonPoole ♦

Thanks @SimonPoole. Would care to enumerate these data sources? Also would you know where the map data for Kenya and Nigeria are sourced from?

(06 Mar '18, 08:13) imonike

Larger places are probably OK, but there multiple imports of GNIS data and other such sources by HOT multiple years back that were never cleaned up AFAIK. Essentially you simply need to check the source, likely the original changeset when the data was added. I suspect recent stuff should be a lot better.

(06 Mar '18, 13:33) SimonPoole ♦

I have to admit SimonPoole's comment above was the first thing that I thought of too. GNIS data has been used in a number of places and is mostly rubbish. There are some attempts to clean it up in e.g. Maproulette (not sure there's a current challenge for this data in Africa, but it would surely be a good candidate).

To find other examples of problem data sources in rural Africa, search for named place=village in Overpass and examine a few to see if they actually match any imagery. An example problem changeset is (there's no source on any data there unfortunately).

(06 Mar '18, 13:41) SomeoneElse ♦

@SimonPoole, @SomeoneElse, many thanks for your helpful comments. Will keep all this in mind as I go along. Cheers!!!

(07 Mar '18, 14:35) imonike
showing 5 of 7 show 2 more comments

Not so much an answer more a theory. When i open an editor over a some African countries, and choose to see all traces i find that there are very, very few GPX traces available. Although most Backgrounds that i have used ( in Europe) seem to be accurately aligned we can check them as we fortunately have lots traces available. There may be several reasons for Europe having lots of traces, The main one guess being disposable income as GPSes are/were expensive. OSM started in Europe and it was a few years before Bing and other Aerial backgrounds became available, perhaps because of this we had to use GPSes as the main source. Now smartphones are available, with good gps chips, and in use worldwide I would suggest if mappers upload GPX enough traces to give a good world wide coverage OSM's accuracy could improve everywhere.

permanent link

answered 26 Feb '18, 15:48

andy%20mackey's gravatar image

andy mackey
accept rate: 4%

edited 27 Feb '18, 14:54

Nairobi's substantially east of Greenwich and slightly south of the equator, so I'm guessing "lat and long being mixed up" rather than "actually asking about west of Greenwich".

(26 Feb '18, 15:50) SomeoneElse ♦

ok wrong again:)

(26 Feb '18, 15:53) andy mackey

I am dealing with Kenya, so all my degrees are east of zero.

(26 Feb '18, 15:54) imonike

It doesn't look like the lat and long are being mixed up. Isn't there a way that I can upload or send the screen-shot? It would really save all the back and forth

(26 Feb '18, 16:04) imonike

You may be able to edit your question and add the jpeg.

(26 Feb '18, 16:22) andy mackey

I want to give the long and lat of the 6 textboxes spread over Nairobi and surrounding regions, starting from the most westerly to the most easterly. A box near Riruta lat: -1.29 lon:36.89, a box near Kawangware lat: -1.30 lon: 36.86, south of Nairobi lat: -1.27 lon: 36.83, close to Eastleigh lat: -1.29 lon:36.79, close to Buru Buru lat:-1.28 lon:36.76 and close to Donholm lat: -1.29 lon 36.73. You would notice that the longitudes are decreasing moving from west to east. It ought to be the other way round. It also doesn't look like the lon and lat values are being mixed up.

(26 Feb '18, 17:03) imonike

Thanks @andy-mackey. I have added the screen-shot. It should be visible now.

(27 Feb '18, 10:18) imonike

From the screen-shot, it can be clearly seen that the longitudes are getting smaller as we move from west to east. It should be the other way around.

(27 Feb '18, 10:21) imonike

The position and your lat lon are displayed here over the OpenStreetMap and something clearly wrong somewhere
Your Dunholm position is located over Riruta and your Riruta located over Dunholm. Similarly with Kawangware and Buru Baru.

On Imgur here

(27 Feb '18, 10:31) nevw

Thanks @nevw. Yeah, I am hoping we can figure out where the problems are coming from. I hadn't heard of the GPSVisualizer before. I am new to mapping.You overlaid the map with the coordinates I supplied?

(27 Feb '18, 12:10) imonike

I pasted the following in the box on the right side and selected "Draw the map"
I think I changed the waypoint options on the left side to permanent labels too.
Buru Buru,close,-1.28,36.76

(27 Feb '18, 12:27) nevw

Thanks @nevw. Now I can't be sure whether the error is from the data, the leaflet API or my handling of the API.

(27 Feb '18, 12:41) imonike

Your coordinates are either wrong or in a different format. How did you obtain them?

(27 Feb '18, 13:02) scai ♦

The names may have been sorted to the wrong set of coordinates?

(27 Feb '18, 13:14) nevw

@scai I obtain them programmatically. Each time I double-click to create a textbox, I save the coordinates in a javascript variable. The method for getting the lat and long values is functionality provided by the leaflet API.

(27 Feb '18, 14:45) imonike

@nevw I don't think so. You see I wasn't clicking on the places named per se. I just used them to give a visual idea of the situation since those places are places whose names showed up on the map and were close to the places I actually clicked. I gave that information before @andy mackey showed me how to upload my screen-shot.

(27 Feb '18, 14:50) imonike

Show us the code your are using to obtain/show these coordinates. This isn't a feature provided by Leaflet out of the box, is it? Also, try a different browser.

(27 Feb '18, 15:10) scai ♦

@scai I have edited the question to show the relevant part of the code.

(27 Feb '18, 15:53) imonike

Thanks @andy mackey.I had thought along similar lines but wanted other opinions since I know so little about mapping. It is hardly to be expected that the quality of gps receivers used for Africa to match those used in Europe and used to the same extent. Assuming that this is indeed the reason for my problems, is there anything I can do in the meantime? Like maybe implementing error-correction algorithms to deal with problematic data, or techniques from cartography or computational geometry that could help ameliorate the situation?

(27 Feb '18, 16:03) imonike

I have used Garmin Etrex Vista HCX and Oregon 450 GPSes so not professional equipment. Judging from my experience ( I have uploaded about a 1000 traces) with a clear view I would say better than 4 meter accuracy. Mapping ways, or aligning Aerial with a mass of traces I think 2 metres is achievable, My android Moto G3 is just about as good but won't do points every second. So pass the word, "upload those traces".

(27 Feb '18, 19:43) andy mackey

If averaged waypoints, that is when a gps records for a time at a fixed known point, for better accuracy could maybe be used to fix points that are identifiable on background may be worth a try.

(27 Feb '18, 19:52) andy mackey

Many thanks @andy mackey. I was hoping for something that could deal with the data as is. While clearly uploading traces is the ultimate solution, I am afraid I don't think that would happen quick enough for my project. Thanks a lot for the help.

(28 Feb '18, 14:06) imonike
showing 5 of 23 show 18 more comments
Your answer
toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 26 Feb '18, 14:03

question was seen: 2,403 times

last updated: 07 Mar '18, 14:35

NOTICE: is being shutdown on 1st March 2024. Please use the OpenStreetMap Community Forum