Author Topic: LIVE FLIGHTS MAP returns to DEPARTURE AIRPORT after every page refresh  (Read 268 times)

quepsi83

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Ok. The topic says it all.  And I've looked at VAM code and recognize where this situation is coded.   Here is a simple snippet I copied off Google's KB relevant to how the Map operates...

SAMPLE JS
=======
{
  var uluru = {lat: -25.344, lng: 131.036};

  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: uluru
  });

}
=======
END SNIPPET

Clearly center: uluru contains the instruction CENTER and the POSITION where to center  "uluru' - the variable - is hard coded in this example.  It's the same construct as I see in VAM's code.... except that the lat/lon to center on is DEPARTURE ICAO.

However.. as I look at the FLIGHTS DATA Tab of SIMACARS - during a flight - LAT and LON are constantly updating. The new thought is...

a) Is it possible to capture LAT/LON from SIMACARS during a flight and use that constantly updating lat/lon data to drive the map and display the plane icon?
b) Is the databse TABLE "vam_track" an adequate source of CONSTANTLY UPDATING LAT/LON?
c) In my VAM... that table contains 31,433 records as of a few minutes ago... is this table updated at pre-determined intervals?
d) Is there anyone out there that can shed some light  on what's happening on the backend?

Using a comparison of projectFLY's live flights map... its functionality is 100% what I'd like to achieve for myself and the good of ALL VAM users.  Can I get a witness???

Cheers,

Keith


UPDATE:

After watching the latitude and longitude columns in VAM_LIVE_FLIGHTS table over a 30 minute spread, these two columns are being updated by SIMACARS. So, a focused direction now exists...

Cheers,

Keith
« Last Edit: July 29, 2018, 09:13:38 PM by quepsi83 »

Timothee

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
So I will start with answering your questions first before I will start with my concerns.

a) Yes, the data you are looking for is in the table vam_live_flights and is updated every 60 seconds by SIMAcars
b) The table vam_track is "static" and only updated once a pilot sends his report
c) As stated in b) this is not the data you are looking for
d) Sure

SIMAcars is updating vam_live_flights and vam_live_acars every 60 seconds. vam_live_flights contains one row for every active flight. vam_live_acars contains multiple rows per flight, the data is used to display the flight track on the map.

As you already noticed, the map loads the departure airport of a flight. This is due to the SQL query, selecting the first coordinates in vam_live_acars. This will return always the departure aiport so its useless. It would make more sense to get the coordinates from vam_live_flights.

However, you want a tracking map. This is easy to achieve, just correct the SQL query. But, what you probably didn't thought about, what do you want to track if you have multiple active flights?

Because of this, I set the coordinates in our VA to 0, 0 to display more or less the whole world. Sure there is no fancy tracking but as I said, as soon you have more than one flight you don't know anymore what you want to track.

Code: [Select]
[...]
var var_location = new google.maps.LatLng(0, 0);
var var_mapoptions = {
center: var_location,
zoom: 2,
[...]
« Last Edit: July 29, 2018, 09:43:11 PM by Timothee »

quepsi83

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Timothee.

Many thanks for that response.   You've helped shine the light so to speak.  Thanks.

Now the latter part of your response is what intrigues me... Yeah...   Understanding your settings 0,0 to display the World is a great 'fix'.   That nugget introduces the NEXT item you pointed out - what to do when there are multiple live flights?

I'm thinking...

a) the live flights table will THEN have multiple rows (really) where each row will represent a single active CALLSIGN.  Right?
b) working with that thought process... being able to query the live flights table will produce tracking for each and every live CALLSIGN?
c) the LAT/LON column values can then be passed to the VARIABLES?
d) via a code modification and a loop... the now updated variables can be pushed to the Maps API and "Viola!"  We're done.   Global moving map tracking for the entire VA?

I'm presently looking at "vam_live_flights_map.php" code... and the answer to the riddle has to lie in the multiple live VA flights (CALLSIGNS) within the table to learn the LAT/LON of each (doesn't matter how many) flight and PASS these individual positions to the Map?

Please be assured... There is no argument intended here... just recognition that IF world-renowned Flightradar24® and projectFLY® can display multiple active planes (live flights) on a Google Map... and we're pleased with looking a real time progress of planes on either of those two engines, then my belief (and I've believed worse things in my life before... LOL) is the "PRIZE" is within the code... and tweaking and such...

Again... Many many thanks for your response Timothee.  I will dig deeper and perhaps pull out the last two hairs on my bald head getting to a fix.   The way I see it... If Flightradar24® and projectFLY® can do this thing? VAM... sure as h@#> can do it too.   LOL

As always,

Cheers,

Keith


EDITED:  In my iten d) above... Let me use the term DISPLAY instead of TRACKING... because to actualy TRACK any one of multiple active flights may yet involve more coding tweaks... but code is code and we are free to think... LOL

Oh! And then there is that page refresh ugly business to deal with too.  But that may be unavoidable because the underlying (and updated) Map still has to be re-drawn after each update... Right....

FURTHER EDITS:

line#28 reads

$sql_map = "select plane_type,ias,flight_id,u.gvauser_id as gvauser_id,u.callsign as callsign,u.name as name,gs,altitude,surname,departure,arrival,latitude,longitude,flight_status,heading,perc_completed,
            pending_nm, a1.latitude_deg as dep_lat, a1.longitude_deg as dep_lon , a2.latitude_deg as arr_lat, a2.longitude_deg as arr_lon , network
            from vam_live_flights lf, gvausers u , airports a1, airports a2 where u.gvauser_id=lf.gvauser_id and lf.departure=a1.ident and lf.arrival=a2.ident";

If you notice the WHERE clause... this portion of the clause LINKS (( u.gvauser_id=lf.gvauser_id )) the 'flying' PILOT/CALLSIGN with the LIVE FLIGHTS PILOT/CALLSIGN... Maybe this could be a factor when dealing with multiple live flights?   I gotta try an edit here.

line#122 I see where you've modded the "0,0"... Cool

I'm gonna leave my line#122 alone for the moment and concentrate on the query.

Thanks



« Last Edit: July 29, 2018, 11:26:39 PM by quepsi83 »

Timothee

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
The SQL query you pasted isn't the one responsible for the map coordinates. There are the following lines just below:

Code: [Select]
[...]
$sql_map2 = "select * from vam_live_acars where flight_id='".$row["flight_id"]."' order by id asc";
if (!$result2 = $db_map->query($sql_map2)) {
die('There was an error running the query  [' . $db_map->error . ']');
}
while ($row2 = $result2->fetch_assoc()) {
$flights_coordinates ["gvauser_id"] = $row2["gvauser_id"];
$flights_coordinates ["latitude"] = $row2["latitude"];
$flights_coordinates ["longitude"] = $row2["longitude"];
$flights_coordinates ["heading"] = $row2["heading"];
$datos [$index2][$index] = $flights_coordinates;
$index ++;
}
[...]
var var_location = new google.maps.LatLng(<?php echo $datos[0][0]["latitude"]; ?>,<?php echo $datos[0][0]["longitude"]; ?>);
[...]

As you will see, the source of the coordinates is vam_live_acars (sorted ascending). Obviously the map can only have one view location, so the location is set to the first coordinates found in vam_live_acars. This will always return the departure airport of the first flight (in case multiple flights are active). Don't get me wrong, the query is used to display the current flight path of each flight so it needs to be there, but it can not be used to set the map coordinates.

What you probably could do is implementing the tracking of the selected aircraft, quite similiar to the follow mode in Flightradar24. But to achieve this a complete rewrite of the current map would be necessary. Currently VAM reloads the complete page to refresh the map. It would be much smoother to reload only the markers. This is just an idea and not something I have done already.

Whatever you have in mind doing, for the current coordinates of each pilot the table vam_live_flights is your friend. There is one line per flight including the coordinates since the last update from SIMAcars.


VA Pilot

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • EUROJET
This issue is bothering me since I started to use VAM.
I haven´t looked into the files yet so this is just an idea: Why not do the sql call with each map refresh and count the rows/data sets.
If you could output the table as an array (like $live_flights = array( "$flight_no1", "$flight_no2", ...), you could probably use foreach or a for loop to create a marker for each flight.
I will play arround with MySQL a bit and test a few ideas.

Regards
Tim
CEO and admin of https://eurojetva.eu :)

Timothee

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
This issue is bothering me since I started to use VAM.
I haven´t looked into the files yet so this is just an idea: Why not do the sql call with each map refresh and count the rows/data sets.
If you could output the table as an array (like $live_flights = array( "$flight_no1", "$flight_no2", ...), you could probably use foreach or a for loop to create a marker for each flight.
I will play arround with MySQL a bit and test a few ideas.

Regards
Tim

This isn't really the issue here. The markers for every plane etc. works perfectly fine, even if multiple flights at the same time are active. What we are talking about are the initial coordinates the map is centered on when loaded.

quepsi83

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Hi Timothee... We are truly focused in the right direction!!!   And your pointer to the piece of code is ABSOLUTELY correct!!!   I've been in touch with the Google Javascript API guy for my earlier encounter (the KEY) and he's pointed me in a great direction to...

a) mod the call to the API
b) refresh the Map exclusive of refreshing the STATIC page - no need to refresh the page as the Map is the only thing changing
c) eliminate that pesky 'every 60 second' pothole on an otherwise smooth interstate highway... Oh Yeah!!!

And, as bad luck would have it, my phone has been ringing non-stop with business... tweaking .PHP and testing has bnow taken a back seat. But I will resume and update with my progress.

As always,

Cheers Keith

quepsi83

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Ok! Looking at the .PHP script...

a) on MY line #123 it originally had a COMMENT OUT "//" on the line...
           var var_location = new google.maps.LatLng(<?php echo $datos[0][0]["latitude"]; ?>,<?php echo $datos[0][0]["longitude"];
I've removed the COMMENT OUT as shown above... Saved and returned to VAM.  No apparent damage done!  Then again.. "Ain't nobody flying..." so no map is displayed.

b) anyway, at that point... the SCRIPT would have dropped OUT of the "WHILE" construct... then continue to execute (essentially) the update to the Map... only to return to the WHILE loop whereby the NEXT ELEMENT in the array would be parsed - the next live flight - and so on... until no more ARRAY elements and STOP.  Right?


Unfortunately... because of interruptions here in the Man Cave... I am unable to do a flight... far more get two pilots up in the air to test if this is a correct attempt on a fix.... or whether I'll need the demolition crew.

QUESTION:  That line # 123 in MY code... with the comment OUT?  Was that also your situation on your end?   If, not true... then I may have inadvertently commented out that line somewhere along my poking around. Can you confirm that please?  Meaning... I need to document EVERYTHING I try so that I can put the pieces back together... My bad!

Thank you very much...

Keith

quepsi83

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
I managed to get a short flight going from FAOR-FQBR - by directly setting it up in SIMACARS.  I edited SIMACARS .DB3 Airports table and applied the same correction of FAJS/FAOR as I did preciously to VAM Airports table. SIMACARS had no problem recognizing FAOR.  That's seems to have worked.

Going back to VAM and the Map display? Everything works after I removed that comment "//" out from... what is it... line #123?

No matter what other achievements at modding this Map functionality... we're still gonna need the Page Refresh cause the live flights LOG entry sits on the STATIC page and we have the various stages of the flight from TAXI, CLIMB, etc which won't ger updated if the page isn't refreshed... "Bummer!"

The MouseClick() and the MouseOver() functions like expected.

My only other lack of reporting has to do with NOT having a few guys up and flying at this time.  Anyway... the path is laid out.

Thank you very much guys for all of your inputs and assists with the thought process.   Should I come up with a small nugget? I'll report back.


Good nite,

Keith

quepsi83

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: LIVE FLIGHTS MAP returns to DEPARTURE AIRPORT after every page refresh
« Reply #9 on: August 01, 2018, 09:36:18 PM »
https://imgur.com/JASgTuS

Just got back to the man cave after some appointments.  The link above shows my current homepage and a 20% progress on a long haul from, Male up to Stansed... 11:52 oh yeah.    I am getting a warm 'n fuzzy about where this Map mod might take me by the time I move from beta to alpha.    This is just my wish... how I'd want my VA homepage to look... just the active flights on a Map like Flightradar24 and projectFLY... the track log to me was distracting after carefully studying Flightradar24's and projectFLY's Map renders.  So I...
  • yanked the TRACK LOG... kept thinking about having to scroll the page if a lot of pilots were flying at the same time... that'll push the Map further down the page... didn't want to scroll
  • am tossing coins about a wider DIV that'll allow me to either keep the map at is's current size AND give me some realestate over on the left so I can kick that Popup further left AND separate it from the Map
  • can now focus on the Map and Popup refresh in sync
  • hopefully shut down the page refresh altogether... ain't nothing but a static page with that track log now departed
  • answer more phone calls and drink more coffee
  • can give up making pictures in exchange for writing code.  What the what?

Thanks again to you guys who lent 'direction'. Greatly appreciated for shizzle,

Cheers,

Keith