js-variable in function einfügen

Lothar1951

Mitglied
Hallo zusammen,

brauche noch mal Eure Hilfe. Ich möchte eine ja-Variable in eine Funktion einbinden. Anbei mein Code:

Code:
function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 8,
    center: {lat: 54.12917, lng: 11.64417}
  });

  setMarkers(map);
}

val LG = <%=lg%>;

// Data for the markers consisting of a name, a LatLng and a zIndex for the
// order in which these markers should display on top of each other.
var beaches = [
  ['Ostseecamp Seeblick', 54.12917, 11.64417, 4],
  ['Campingpark Buntspecht ****', 52.6556, 12.43445, 5],
  ['Campingplatz Liebeslaube', 53.93153, 11.29085, 3],
  ['Campingplatz Niendorf GmbH', LG , 11.27058,2],
  ['Maroubra Beach', -33.950198, 151.259302, 1]
];

Um LG geht es!

Gruß Lothar
 
Jetzt habe ich es so gemacht, aber ohne Erfolg!!!

Code:
var LG = '<%=lg%>';

function initMap(LG) {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 8,
    center: {lat: 54.12917, lng: 11.64417}
  });

  setMarkers(map);
}

var beaches = [
  ['Ostseecamp Seeblick', 54.12917, 11.64417, 4],
  ['Campingpark Buntspecht ****', 52.6556, 12.43445, 5],
  ['Campingplatz Liebeslaube', 53.93153, 11.29085, 3],
  ['Campingplatz Niendorf GmbH', LG, 11.27058,2],
  ['Maroubra Beach', -33.950198, 151.259302, 1]
];

Gruß
 
Wie und wo in einer Funktion?
Das hier funktioniert alles (habe mal verschiedenes getestet)
HTML:
<html>
    <head>
        <title>Test</title>
        <script type="text/javascript">

        var LG = '<%=lg%>';
        console.warn(LG);

        function vari(LG) {
            var vari2 = 'Variable2';
           
            console.warn(LG);
            LG = LG+'hinzugefügt';
            console.warn(LG);

            console.warn(vari2);
        }

        vari(LG);
        </script>
    </head>
    <body>
    </body>
</html>
 
Zum Beispiel möchte ich LG in diese Funktion einfügen.

Code:
var LG = '<%=lg%>';

function initMap(Name, LG) {

  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 8,
    center: {lat: 54.12917, lng: 11.64417}
  });

  setMarkers(map);
}

// Data for the markers consisting of a name, a LatLng and a zIndex for the
// order in which these markers should display on top of each other.
var beaches = [
  ['Ostseecamp Seeblick', 54.12917, 11.64417, 4],
  ['Campingpark Buntspecht ****', 52.6556, 12.43445, 5],
  ['Campingplatz Liebeslaube', LG, 11.29085, 3],
  ['Name', 53.9293, 11.27058,2],
  ['Maroubra Beach', -33.950198, 151.259302, 1]
];

Gruß
 
Jetzt habe ich es so verändert, funktioniert trotzdem nicht.

Code:
var BG = 53.9293;

function initMap(Name, BG) {

  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: <%=zoom%>,
    center: {lat: 54.12917, lng: 11.64417,}
  });

  setMarkers(map);
}

// Data for the markers consisting of a name, a LatLng and a zIndex for the
// order in which these markers should display on top of each other.
var beaches = [
  ['Ostseecamp Seeblick', 54.12917, 11.64417, 4],
  ['Campingpark Buntspecht ****', 52.6556, 12.43445, 5],
  ['Campingplatz Liebeslaube', "+BG+", 11.29085, 3],
  ['Name', 53.9293, 11.27058,2],
  ['Maroubra Beach', -33.950198, 151.259302, 1]
];

Ich möchte die Variable BG in die Funktion einfügen.

Gruß
 
Du hast da zu viele Hochkommas drin:
Code:
['Campingplatz Liebeslaube', "+BG+", 11.29085, 3]
So ist es richtig:
Code:
['Campingplatz Liebeslaube', BG, 11.29085, 3]
 

Neue Beiträge

Zurück