Socrata Example B

new

by Brent Coder

HTML

<script src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>
<title>Google Maps Example</title>

<body>
  <div id="map" />
</body>

CSS

#map {
   height: 480px;
   width: 640px
 }

JavaScript

$(window).load(function() {
  // Construct the catalog query string
  url = 'https://www.thedatazone.ca/resource/dukt-62fs.json';
  var infoWindow = new google.maps.InfoWindow();
  var marker = [];
  // Intialize our map
  var center = new google.maps.LatLng(44.651070, -63.582687);
  var mapOptions = {
    zoom: 6,
    center: center
  }
  var map = new google.maps.Map(document.getElementById("map"), mapOptions);

  // Retrieve our data and plot it
  $.getJSON(url, function(data, textstatus) {
    //console.log(data);

    $.each(data, function(i, entry) {
      //try {
         // console.log('here now');
         // entry.location.coordinates["0"]
         // console.log('I guess you do exist')
     // } catch (e) {
     // entry.location.coordinates["0"].push(0);
     // entry.location.coordinates["1"].push(0);
     // console.log('An error has occurred: '+e.message);
      
    //  }
    
   
      if (typeof (entry.location) !== 'undefined') {
        console.log(entry.aan);
        console.log(entry.location.coordinates);
        marker = new google.maps.Marker({

          position: new google.maps.LatLng(entry.location.coordinates["1"],entry.location.coordinates["0"] ),
          map: map,

          title: entry.municipal_unit + ' ' + entry.aan,
          id: i
               
           });     
       } else {
      
    
                console.log('here');
      
 
     }

      //console.log(entry);
      if (typeof (entry.location) !== 'undefined') {
      infowindow = new google.maps.InfoWindow({
        //console.log(data.district_name[i]);
        //content: data[i].district_name
        position: new google.maps.LatLng(entry.location.coordinates["1"], entry.location.coordinates["0"]),

        content: entry.municipal_unit + ' ' + entry.aan,
        id: i
      });
      } else {
      
      }
      (function(marker, data) {
        google.maps.event.addListener(marker, "click", function(e) {
          //Wrap the content inside an HTML DIV in...