I've been breaking my head the greater part of the day on getting correct output from longitude and latitude data. I know this data is correct by plotting it in google maps. For example I will show the data for these lat and long coordinates: Longitude: 4.905396 Latitude: 52.364643
When plotted in google maps it shows the correct location which is Amsterdam in The Netherlands:
Now when I plot this in my application it looks as follows:
And yes google maps is a 2D representation and mine is 3D but this was just to prove that the longitude and latitude values are correct so if my formula of converting them to 3D space is correct they should appear on the same spot.
I've been reading through a lot of articles on the web as well as stackoverflow itself. I've been through these articles and applied all of the different types of formula's I saw:
Convert Latitude and Longitude to point in 3D space
and
3D coordinates on a sphere to Latitude and Longitude
These two seemed to have the cleared explanation with good examples but nothing seems to work. What I am doing right now is calculating the position in 3D space and then normalizing it and using it as a direction to draw a line with a dot on the end as you can see in the screenshot of my application. This doesn't differ of just drawing a line from the center to the calculated position when using the radius of the earth which is used in most examples.
My current formula is:
X = r * cos(latitude) * cos(lontitude);
Y = r * cos(latitude) * sin(longitude);
Z = r * sin(latitude);
Which is wrong I know but Ive went through all the examples I saw on the web and none showed me correct data. By testing it with data from google maps I know that at least the input is correct.
Update1:
I checked the topology of my texture, this is what happens when its latitude and longitude are 0.0000 and 0.0000:
So this means that this is wrong already but its off with an odd offset, as google maps shows it it should be like this:
The green arrow is the 0.0000, 0.0000 mark. So mine is off that's obvious, its off to the side. I'm thinking it might ( dont think/hope so ) be the texture, I'm using this one: http://naturalearth.springercarto.com/ne3_data/16200/textures/2_no_clouds_16k.jpg
Which I obtained from: Shadedrelief Natural Earth textures
Update 2: I've checked the topology of my sphere with texture, it seems to be off for 0.0 and 0.0 but I'm also doubting my formula. I've tried a lot of different ones from the web and some of them get the same 0.0 0.0 as my first formula but a lot don't. My longitude and latitude are in degrees with the -180~180 and -90~90.
Update 3: This is the view of a plot on amsterdam, its off a little bit, just like the 0.0 0.0 lat/long piont. Somewhere either the map or calculations are wrong I guess. I'll try adapting the texture to be shifted a little bit.