N402KC Posted May 20, 2010 Share Posted May 20, 2010 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 Quote Link to comment Share on other sites More sharing options...
trq Posted May 20, 2010 Share Posted May 20, 2010 Of course there are ways to do this, seems a pretty straight forward task. Where exactly are you stuck? Quote Link to comment Share on other sites More sharing options...
N402KC Posted May 21, 2010 Author Share Posted May 21, 2010 Im stuck on trying to figure out what sort of statement or code i a should do that will repeat all of the code, but the different variables. Quote Link to comment Share on other sites More sharing options...
trq Posted May 21, 2010 Share Posted May 21, 2010 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);"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.