Search code examples
grailsgoogle-maps-api-3gsp

Grails / Groovy Attribute value quote wasn't closed : Google Visualization API - data from Domain Class


I am using GGTS: 3.6.4, Grails: 2.4.4 jdk 1.7.51 google-visualization:1.0

I am trying to pass data from a domain class to my view to display a map using the Google Visualization plug-in. I believe I am passing this data to my GSP incorrectly. I can make the data render on screen, in text, in the acceptable format, please see my GSP for def mapData.

When I use

def mapData =[<g:each in="${places}" var="place" status="i">[${place.lat}, ${place.lon}, "${place.name }"],</g:each>]

I get this error: Message:Attribute value quote wasn't closed (elementId="map" columns= "${mapColumns}" data= "[

Any tips on how I can change my GSP to get the data from my domain class?

Domain Class:

package zmapapp

class ThingLoc {
String name
Float lat
Float lon

static constraints = {

    lat()
    lon()
    name()
  }
}

Controller:

  package zmapapp


class ThingLocController {

def scaffold = true


def map (){
    def places = ThingLoc.list()
    [places: places]
}
}

GSP:

<html>
<head>
    <title>Google Visualization API plugin</title>
    <meta name="layout" content="main" />
    <gvisualization:apiImport/>
</head>
   <body>
   <%

      def mapColumns = [['number', 'Lat'], ['number', 'Lon'], ['string', 'Name']]
      def mapData = [[37.4232, -122.0853, 'Work'], [37.4289, -122.1697, 'University'], [37.6153, -122.3900, 'Airport'], [37.4422, -122.1731, 'Shopping']]


   %>
   <script type="text/javascript">
      function selectHandler(e) {
          alert('A table row was selected');
      }

      function readyHandler(e) {
          console.log('Table is ready');
      }
   </script>

   <h2>See Map Below   </h2>

   <gvisualization:map elementId="map" 

   columns= "${mapColumns}" 
   data= "${mapData}"     />



   <table cellpadding="2" cellspacing="0">

         <td>
            <a href="http://developers.google.com/chart/interactive/docs/gallery/map">Map</a>
         </td>
         <td>
            <div id="map" style="width: 400px; height: 300px"></div>
         </td>
      </tr>
   </table>


           [<g:each in="${places}" var="place" status="i">[${place.lat}, ${place.lon}, "${place.name }"],</g:each>]


</body>


Solution

  • I ended up not using the def mapColumns or mapData and instead used the google syntax found here: https://developers.google.com/chart/interactive/docs/gallery/map

    here's my update gsp:

        <html>
     <head>
         <title>Dat Map tho</title>
    <meta name="layout" content="main" />
    <gvisualization:apiImport/>
    
     <script type="text/javascript">
    
    google.load('visualization', '1', { 'packages': ['map'] });
    google.setOnLoadCallback(drawMap);
    
     function drawMap() {
     var data = google.visualization.arrayToDataTable([
       ['Lat', 'Long', 'Name'],
    
       <g:each in="${places}" var="place" status="i">[${place.lat}, ${place.lon}, "${place.name }"],</g:each> 
    
       ]);
    
    var options = { showTip: true };
    
    var map = new google.visualization.Map(document.getElementById('chart_div'));
    
    map.draw(data, options);
     };
    </script>
    
    </head>
    <body>
    
      <div id="chart_div"></div>
    <br><br>
    
      <a   href="http://developers.google.com/chart/interactive/docs/gallery/map">Map Visualization Information</a>
    
      </body>
         </html>