What is sc_temp_key?

I am trying to create a blank application to run a Google map using Google Maps API and selecting the data from a database within scriptcase.

Some of the code is similar to what was running in the Google Heat Maps tutorial, but I had to change a lot of it to get it to work. As you will see below, it has been simplified to pull the data and put in format for a simple markers map using the Google Maps API…

 $LatLong = array();
  $i = 0;
  
  sc_lookup(ds,"SELECT latitude,longitude,first_name,surname FROM staff WHERE active=1");
  
  for($i=0;$i<count({ds});$i++){
      $LatLong[] = [
         'lat' => $ds[$i][0],
         'lng' => $ds[$i][1],
         'title' => $ds[$i][2] . " ". $ds[$i][3]
      ];
  }
  
  
  ?>
  
  <!DOCTYPE html>
  <html>
    <head>
      <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
      <meta charset="utf-8">
      <title>Locations</title>
      <style>
        /* Always set the map height explicitly to define the size of the div
         * element that contains the map. */
        #map {
          height: 80%;
        }
        /* Optional: Makes the sample page fill the window. */
        html, body {
          height: 100%;
          margin: 0;
          padding: 0;
        }
      </style>
    </head>
    <body>
    
    <div id="map"></div>
    
      <script>
  
      function initMap() {
     var myLatLng = {lat: 37.3320045, lng: -122.0329699};
  
     var map = new google.maps.Map(document.getElementById('map'), {
       zoom: 12,
       center: myLatLng
     });
  
  var latLong = <?php echo json_encode($LatLong)?>;
  
  // iterate over latLong and create markers:
  
  for (var key in latLong) {
       var marker = new google.maps.Marker({
          position: {lat: latLong[key]['lat'], lng: latLong[key]['lng']},
           map: map,
           title: latLong[key]['title']
       });
  
  }
      </script>
    
  
    
      <script async defer
      src="https://maps.googleapis.com/maps/api/js?key=APIKEY&callback=initMap">
      </script>
  
    </body>
  </html>
  
  <?php
 

This is working fine, until I run it and at the point below, it stops, where in the output it gives ‘$this->sc_temp_key’ which I can’t seem to find anywhere online?

This;

 for (var key in latLong) {
       var marker = new google.maps.Marker({
          position: {lat: latLong[key]['lat'], lng: latLong[key]['lng']},
           map: map,
           title: latLong[key]['title']
       });
 

Turns in to this;

 for (var key in latLong) {
       var marker = new google.maps.Marker({
          position: {lat: latLong$this->sc_temp_key['lat'], lng: latLong$this->sc_temp_key['lng']},
           map: map,
           title: latLong$this->sc_temp_key['title']
       });
 

Seems to turn

[key]

in to

$this->sc_temp_key

Any help on this would be appreciated.

Thanks

Ok, strangely, I just tried something else, and changed the

['lat']

next to [key] to

[lat]

to see what happened and suddenly that outputs;

$this->sc_temp_lat

Is there anyway I can get around this to get the objects to work within scriptcase?

This issue is due to Scriptcase’s code interpreter replacing some tokens with internal variables. A simple way to avoid this is to put a space inside the brackets, so the interpreter will skip those.

Ex.:


for (var key in latLong) {
       var marker = new google.maps.Marker({
          position: {lat: latLong[ key]['lat'], lng: latLong[ key]['lng']},
           map: map,
           title: latLong[ key]['title']
       });

We currently have no better way to escape those tokens, but I’ll look into that and check if it is possible to implement.

Much appreciated, that helps! Thank you