Jump to content

PHP to Write Javascript


N402KC

Recommended Posts

Hi guys,

 

Working with google maps here and what i am trying to do is have php write the javascript to add onto the map. Here is the javascript

 

var flightpath1 = [];

point = new GLatLng(29.645419, -95.278889);
flightpath1.push(point);
bounds.extend(point);
marker16 = new GMarker(new GLatLng(29.645419, -95.278889), { icon: iconGreen});
map.addOverlay(marker16);
point = new GLatLng(32.847111, -96.851778);
flightpath1.push(point);
bounds.extend(point);
marker17 = new GMarker(new GLatLng(32.847111, -96.851778), { icon: iconBlue});
map.addOverlay(marker17);

map.addOverlay(new GPolyline

 

everytime a new entry is added to the database, there will be a new code

so say there is one person online. It will show the code above. But if there is a new entry into the database, then a new code in the same format but with different variables will be added. For example, Take the one above has example 1, and say a new pilot logs in, then this code will be added under it;

 

 

var flightpath2 = [];

point = new GLatLng(33.434278, -112.011583);
flightpath2.push(point);
bounds.extend(point);
marker18 = new GMarker(new GLatLng(33.434278, -112.011583), { icon: iconGreen});
map.addOverlay(marker18);
point = new GLatLng(39.861656, -104.673178);
flightpath2.push(point);
bounds.extend(point);
marker19 = new GMarker(new GLatLng(39.861656, -104.673178), { icon: iconBlue});
map.addOverlay(marker19);

map.addOverlay(new GPolyline(flightpath2, '#02356a#', 1));

 

So once there are multiple people logged in, it should look like this;

 

var flightpath1 = [];

point = new GLatLng(29.645419, -95.278889);
flightpath1.push(point);
bounds.extend(point);
marker16 = new GMarker(new GLatLng(29.645419, -95.278889), { icon: iconGreen});
map.addOverlay(marker16);
point = new GLatLng(32.847111, -96.851778);
flightpath1.push(point);
bounds.extend(point);
marker17 = new GMarker(new GLatLng(32.847111, -96.851778), { icon: iconBlue});
map.addOverlay(marker17);

map.addOverlay(new GPolyline(flightpath1, '#02356a#', 1));


var flightpath2 = [];

point = new GLatLng(33.434278, -112.011583);
flightpath2.push(point);
bounds.extend(point);
marker18 = new GMarker(new GLatLng(33.434278, -112.011583), { icon: iconGreen});
map.addOverlay(marker18);
point = new GLatLng(39.861656, -104.673178);
flightpath2.push(point);
bounds.extend(point);
marker19 = new GMarker(new GLatLng(39.861656, -104.673178), { icon: iconBlue});
map.addOverlay(marker19);

map.addOverlay(new GPolyline(flightpath2, '#02356a#', 1));


var flightpath3 = [];

point = new GLatLng(41.411690, -81.849794);
flightpath3.push(point);
bounds.extend(point);
marker20 = new GMarker(new GLatLng(41.411690, -81.849794), { icon: iconGreen});
map.addOverlay(marker20);
point = new GLatLng(39.175361, -76.668333);
flightpath3.push(point);
bounds.extend(point);
marker21 = new GMarker(new GLatLng(39.175361, -76.668333), { icon: iconBlue});
map.addOverlay(marker21);

map.addOverlay(new GPolyline(flightpath3, '#02356a#', 1));


var flightpath4 = [];

point = new GLatLng(41.785972, -87.752417);
flightpath4.push(point);
bounds.extend(point);
marker22 = new GMarker(new GLatLng(41.785972, -87.752417), { icon: iconGreen});
map.addOverlay(marker22);
point = new GLatLng(33.434278, -112.011583);
flightpath4.push(point);
bounds.extend(point);
marker23 = new GMarker(new GLatLng(33.434278, -112.011583), { icon: iconBlue});
map.addOverlay(marker23);

map.addOverlay(new GPolyline(flightpath4, '#02356a#', 1));


var flightpath5 = [];

point = new GLatLng(38.748697, -90.370029);
flightpath5.push(point);
bounds.extend(point);
marker24 = new GMarker(new GLatLng(38.748697, -90.370029), { icon: iconGreen});
map.addOverlay(marker24);
point = new GLatLng(41.785972, -87.752417);
flightpath5.push(point);
bounds.extend(point);
marker25 = new GMarker(new GLatLng(41.785972, -87.752417), { icon: iconBlue});
map.addOverlay(marker25);

map.addOverlay(new GPolyline(flightpath5, '#02356a#', 1));


var flightpath6 = [];

point = new GLatLng(47.449000, -122.309306);
flightpath6.push(point);
bounds.extend(point);
marker26 = new GMarker(new GLatLng(47.449000, -122.309306), { icon: iconGreen});
map.addOverlay(marker26);
point = new GLatLng(47.619861, -117.533833);
flightpath6.push(point);
bounds.extend(point);
marker27 = new GMarker(new GLatLng(47.619861, -117.533833), { icon: iconBlue});
map.addOverlay(marker27);

map.addOverlay(new GPolyline(flightpath6, '#02356a#', 1));


var flightpath7 = [];

point = new GLatLng(32.847111, -96.851778);
flightpath7.push(point);
bounds.extend(point);
marker28 = new GMarker(new GLatLng(32.847111, -96.851778), { icon: iconGreen});
map.addOverlay(marker28);
point = new GLatLng(35.393088, -97.600734);
flightpath7.push(point);
bounds.extend(point);
marker29 = new GMarker(new GLatLng(35.393088, -97.600734), { icon: iconBlue});
map.addOverlay(marker29);

map.addOverlay(new GPolyline(flightpath7, '#02356a#', 1));

 

Please let me know if there is a way to do this. Thanks

Link to comment
Share on other sites

Well, i'm not going through all of that code, but just as an example.

 

<?php
// these could actually come from a database.
$lat = '33.434278';
$len = '-112.011583';

//echo your javascript.
echo "point = new GLatLng($lat, $len);";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.