PDA

View Full Version : Real time flight path on Google Map



mevans
Oct-15-2017, 15:16
I have seen on other threads questions regarding the use of a second monitor to show the Map in Cliffs of Dover and understand that it cannot be done. Also some players not from the UK would like to have a map on a second monitor so they can get use to the names of towns and cities etc. What I have been able to do is to use Google maps to show in real time the position of the players plane as they fly around southern England. Note that this will only work on single player missions and does not show the location of any other aircraft or feature apart for the 11 group airfields which I have added. It also shows 2017 England and not 1940 England. On the screen shot attached you will see the map on the right with a track showing a fight with bombers over Hornchurch airfield. it is not 100% accurate but it is quite close. Unfortunately it does take a bit of time to set up (took nearly 3 months to work it all out) but adds a bit of fun. It would also pay to keep the file name etc. the same until everything works otherwise you will have to edit the files as applicable.

There are two main files involved. The first is Master.txt which needs to be saved as a .cs file. Open the file in a txt editor and copy the contents. Paste the contents into a new txt file and save as Master.cs. At this stage is doesn't matter where it is saved. Open the Cliffs of Dover.txt file, copy the contents and paste into another txt file and save as Cliffs of Dover.php. Again doesn't matter where this is saved at this stage.

There are two things that are needed to be done to make the system work. First you will need to obtain an API key from Google Maps. https://developers.google.com/maps/documentation/embed/get-api-key will show you how to get this. Its quite simple and free. When you get your API key copy and paste it into the Cliffs of Dover.php file in the line near the bottom that over the text YOUR_API_KEY. Don't leave any spaces before of after the key.

The next step is to create a server on your computer which is needed to run the .php file. I used WAMP (which is free) and it works fine. Goggle WAMP download and follow the instructions. It can be a bit tricky but what this will do is allow you to set up a local server on your computer which is eded to run the .php file. WAMP needs to go in your root directory and is run from your hidden icons box on the lower right of your screen.

Once WAMP is downloaded and set up, there will be a folder WAMP64 in your root directory with a subfolder WWW. In WWW folder create another folder called CLOD. It is into this directory that you paste the Cliffs of Dover.php file.

Now the Master.cs file is the programme that runs when you play a mission. It retrieves the x and y coordinates of your aircraft, converts them roughly to lat and long and writes them into a txt file which will be created in your WWW/CLOD folder. The .php file needs to be pasted into same folder as your .mis file (typically C:\Users\name\OneDrive\Documents\1C SoftClub\il-2 sturmovik cliffs of dover - MOD\missions) and given the same name i.e. if you have a mission called London Burning.mis, then copy the .cs file into the same folder and rename it London Burning.cs. You do this for any mission that you want to use the Google Map.

Hopefully now it will all work. When you run it the first time start your mission first. If the word Map appears at the top of the screen then the data is being written into a text file called LatLong.txt in the WWW.CLOD folder. If it doesn't make sure the .cs file is named correctly. If the word Map does appear wait a couple of seconds and then Alt tab and open Chrome. Apparently Chrome is best for Google Maps and WAMP but it may work in other browsers. In the directory box (or whatever it is called) type in localhost/CLOD/Cliffs of Dover.php and press enter. What will now happen is that the .php file should run (may take a second or so) open a map. get the lat,long form the txt file, place a marker on the screen and centre the map on that location. The lat and long are updated every second and as you fly the marker is moved to the new location, a line is drawn from the previous position and the map pans to the new position. The next time you fly, the map will assume that you are at the last know position so I start the mission, Alt Tab to Chrome and refresh then back to CLOD. Refresh the map if you are at a different location.

Hopefully everything will work and you will get a same results as I do. Once it is all working feel free to have a look at the programmes (open in any text editor) and have a play. You can alter the timing interval, have only the marker and no line, have no line or marker and use simply as a map. Add aerodromes or other features as you like. If there are problems I will try to help but I am not a programmer and this is may first attempt at this sort of thing. And many thanks to FearlessFrog who provided the original .cs file that I copied and amended to get the x and y coordinates.

BOO
Oct-15-2017, 16:39
Nice work

There is also this that can be put on a separate monitor and plots made on it

http://il2map.info/map?type=clod_channel

There is an even more detailed one about too.....

TWC_Flug
Nov-04-2017, 00:22
Hey, this is a nice piece of work.

I've been working on a similar project to show 'radar' for our servers.

As part of that, I started out with the idea of putting it on a google map. After a while I gave up on that and used leaflet.js as the map software--it allows you to use any map as your base map, and so we're using an actual IL2 CloD map, which works better in several ways.

However, I messed around with the function to translate CloD coordinates to lat & long, and I thought you might be interested in the results.


public static Point3d Il2Point3dToLongLat(Point3d pos)
{

//Cubic Regression Curve Fit for four points on various corners of the map done
//via https://www.mycurvefit.com/
//Should is accurate to about the 6th decimal place of the lat/long on those four points, but is
//inaccurate by up to 15km (?) on various points around the map
pos.x = -2.017013 + 0.00001256447 * pos.x + 5.532674e-12 * pos.x * pos.x - 6.478475e-18 * pos.x * pos.x * pos.x;
pos.y = 49.01039 + 0.00000923699 * pos.y - 2.674155e-12 * pos.y * pos.y + 7.598837e-18 * pos.y * pos.y * pos.y;

return pos;
}

Based on my experiments, this is somewhat better than the formula you are using in your package. But it still wasn't really as good as I would have liked. For example, when parked on the runway at Gosport it showed my aircraft somewhere in the middle of the ocean offshore.

This could probably be improved on quite a bit if anyone wants to, by say getting a grid of maybe 16 points around the map, getting their CloD coordinates & real-world lat/lon coordinates very carefully, then putting all that into a curve fitting program like the one at https://www.mycurvefit.com/

I didn't investigate it that thoroughly, but my suspicion is that besides the usual issues of turning a 2-d map & coordinate system in real-world lat/lon, there are also some distortions (perhaps deliberate) in the CloD map so that it really doesn't quite match up with the real map in every detail.

FYI, based on my four selected points--which were near but not quite at the four corners of the CloD map, mycurvefit found these 3 formulas to convert (x,y) coordinates in CloD's system to lat/lon:

Formula #1 (linear):

lat =0.00000907759*y+49.0913
lon = 0.00001390456*x - 2.097487

Formula #2 (quadratic):

lat = 49.01703 + 0.000008851254*y+7.476433*10^-13*y^2
lon = -2.041605 + 0.00001312839*x + 1.959212e-12*x^2

Formula #3 (cubic):

lat = 49.01039 + 0.00000923699*y - 2.674155e-12*y^2 + 7.598837e-18*y^3
lon = -2.017013 + 0.00001256447*x + 5.532674e-12*x^2 - 6.478475e-18*x^3

As you can see, I implemented #3 because it was by far the best fit for my four selected points. But I'm not so sure it really is the best--it might have gotten better accuracy on those four specific points by warping more on what went in between, where I didn't have any points.

Anyway, I'm posting them formulas here just in case anyone wants to fiddle with them.

mevans
Nov-04-2017, 12:44
Thanks for that, I'll give them a try.

i did realise that the accuracy wouldn't be that good and have also been trying to improve it but it's probably as accurate as Radar was in 1940. It does work quite well if you turn off the location marker and the track and use it simply as a map. Look out the window to identify landmarks and then work out your location.

i have also been trying to create a Radar of sorts for single mission pilots that would allow them to sit in the cockpit and watch the raids come in. No briefing would be given, the pilot would act as a controller and have to decide which raid to go for, much like the actual controllers in 1940. If they go for the wrong target and it turns back for France they may miss the raid that is going for London for example. My problem is that I haven't been able to work out how to get the enemy location. If someone can provide script on how to obtain the x,y coordinates for enemy AI much appreciated.

Cheers and good luck with your project.

TWC_Flug
Nov-14-2017, 00:30
Thanks for that, I'll give them a try.

i did realise that the accuracy wouldn't be that good and have also been trying to improve it but it's probably as accurate as Radar was in 1940. It does work quite well if you turn off the location marker and the track and use it simply as a map. Look out the window to identify landmarks and then work out your location.

Yes, it's really more of an annoyance than anything. It is really still quite usable, and useful. As I mentioned, I just have a suspicion that there is more at work than just the conversion from flat coordinates to spherical lat/lon. I suspect the map might be distorted just a smidgen here and there. But--that is just a suspicion and I'm not sure one way or the other.


i have also been trying to create a Radar of sorts for single mission pilots that would allow them to sit in the cockpit and watch the raids come in. No briefing would be given, the pilot would act as a controller and have to decide which raid to go for, much like the actual controllers in 1940. If they go for the wrong target and it turns back for France they may miss the raid that is going for London for example. My problem is that I haven't been able to work out how to get the enemy location. If someone can provide script on how to obtain the x,y coordinates for enemy AI much appreciated.

Cheers and good luck with your project.

Well, if you are for a project we have released the source code for the TWC Mission Server and it is all in there:

https://github.com/bhugh/TWC_Mission_Server

There is a whole lot of stuff (and a whole lot of cruft) in there, but if you look for example at TWC M001-MAIN.cs and look for method "listpositionallaircraft" you will see a working example.

That file is here: https://github.com/bhugh/TWC_Mission_Server/blob/master/M001/TWC%20M001-MAIN.cs

The relevant bit is:


if (GamePlay.gpArmies() != null && GamePlay.gpArmies().Length > 0)
{
foreach (int army in GamePlay.gpArmies())
{
//List a/c in player army if "inOwnArmy" == true; otherwise lists a/c in all armies EXCEPT the player's own army
if (GamePlay.gpAirGroups(army) != null && GamePlay.gpAirGroups(army).Length > 0 && (!inOwnArmy ^ (army == playerArmy)))
{
foreach (AiAirGroup airGroup in GamePlay.gpAirGroups(army))
{
aigroup_count++;
if (airGroup.GetItems() != null && airGroup.GetItems().Length > 0)
{
poscount = airGroup.NOfAirc;
foreach (AiActor actor in airGroup.GetItems())
{
if (actor is AiAircraft)
{
AiAircraft a = actor as AiAircraft;
etc.

Then a.Pos() is a Point3d and contains the x,y,z location of the aircraft. So for example you can use a.Pos().x, a.Pos().y, and a.Pos().z.

mevans
Nov-14-2017, 11:03
That's fantastic, should keep me going for a few years.

Hopefully might have something working soon. Cheers