1

大家好,试图找到代码以从谷歌融合表中提取最新坐标并将其作为原点插入到下面的代码中。(var origin1)

GOOGLE Fusion 表设置;

   {
     "kind": "fusiontables#columnList",
     "totalItems": 15,
     "items": [
      {
       "kind": "fusiontables#column",
       "columnId": 0,
       "name": "description",
       "type": "STRING"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 1,
       "name": "kind",
       "type": "STRING"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 2,
       "name": "name",
       "type": "STRING"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 3,
       "name": "placeId",
       "type": "STRING"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 4,
       "name": "info1",
       "type": "STRING"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 5,
       "name": "info2",
       "type": "STRING"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 6,
       "name": "info3",
       "type": "STRING"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 7,
       "name": "info4",
       "type": "STRING"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 8,
       "name": "accuracy",
       "type": "NUMBER"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 9,
       "name": "speed",
       "type": "NUMBER"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 10,
       "name": "heading",
       "type": "NUMBER"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 11,
       "name": "altitude",
       "type": "NUMBER"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 12,
       "name": "altitudeAccuracy",
       "type": "NUMBER"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 13,
       "name": "timestamp",
       "type": "NUMBER"
      },
      {
       "kind": "fusiontables#column",
       "columnId": 14,
       "name": "geometry",
       "type": "LOCATION"
      }
     ]
    }

这是它保留的一些数据,我正在尝试获取“最新”几何坐标并添加我的地图,以提供实时更新。

{
 "kind": "fusiontables#sqlresponse",
 "columns": [
  "description",
  "kind",
  "name",
  "placeId",
  "info1",
  "info2",
  "info3",
  "info4",
  "accuracy",
  "speed",
  "heading",
  "altitude",
  "altitudeAccuracy",
  "timestamp",
  "geometry"
 ],
 "rows": [
  [
   "",
   "",
   "Location at Mon 14/05/2012 13:42:58",
   "",
   "resourceasstring",
   "",
   "",
   "",
   "65",
   NaN,
   NaN,
   NaN,
   NaN,
   1.336966978085E12,
   {
    "geometry": {
     "type": "Point",
     "coordinates": [
      144.9339931215855,
      -37.83169408321385,
      0.0
     ]
    }
   }
  ],
  [
   "",
   "",
   "Location at Mon 14/05/2012 19:20:11",
   "",
   "resourceasstring",
   "",
   "",
   "",
   "1414",
   NaN,
   NaN,
   NaN,
   NaN,
   1.336987211753E12,
   {
    "geometry": {
     "type": "Point",
     "coordinates": [
      145.2516605102396,
      -37.92732182161065,
      0.0
     ]
    }
   }
  ],
  [
   "",
   "",
   "Location at Mon 14/05/2012 19:40:12",
   "",
   "resourceasstring",
   "",
   "",
   "",
   "1414",
   NaN,
   NaN,
   NaN,
   NaN,
   1.336988412041E12,
   {
    "geometry": {
     "type": "Point",
     "coordinates": [
      145.3447657261889,
      -37.91152087158031,
      0.0
     ]
    }
   }
  ],
  [
   "",
   "",
   "Location at Tue 15/05/2012 09:41:57",
   "",
   "resourceasstring",
   "",
   "",
   "",
   "65",
   NaN,
   NaN,
   NaN,
   NaN,
   1.337038917553E12,
   {
    "geometry": {
     "type": "Point",
     "coordinates": [
      144.9339498133275,
      -37.8317148043096,
      0.0
     ]
    }
   }
  ],

这是显示地图的 html/java 代码;

 <!DOCTYPE html>
    <html>
      <head>
        <title>Google Maps API v3 Example: Distance Matrix</title>
        <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

        <style>
          body {
            margin: 20px;
            font-family: courier, sans-serif;
            font-size: 12px;
          }
          #map {
            height: 480px;
            width: 640px;
            border: solid thin #333;
            margin-top: 20px;
          }
        </style>

        <script>
        //Taken and adopted from https://developers.google.com/maps/documentation/javascript/distancematrix
        //Need to make the fusion table part work next!!
          var map;
          var geocoder;
          var bounds = new google.maps.LatLngBounds();
          var markersArray = [];

//var origin1 is where i want it to pull the data from the fusion table.
          var origin1 = new google.maps.LatLng(-37.83169408321385,144.9339931215855);
          var destinationA = 'glen iris, Australia';


          var destinationIcon = 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=D|FF0000|000000';
          var originIcon = 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=O|FFFF00|000000';

          function initialize() {
            var opts = {
              center: new google.maps.LatLng(-37.83,144.93),
              zoom: 20,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById('map'), opts);
            geocoder = new google.maps.Geocoder();
          }

          function calculateDistances() {
            var service = new google.maps.DistanceMatrixService();
            service.getDistanceMatrix(
              {
                origins: [origin1],
                destinations: [destinationA],
                travelMode: google.maps.TravelMode.DRIVING,
                unitSystem: google.maps.UnitSystem.METRIC,
                avoidHighways: false,
                avoidTolls: false
              }, callback);
          }

          function callback(response, status) {
            if (status != google.maps.DistanceMatrixStatus.OK) {
              alert('Error was: ' + status);
            } else {
              var origins = response.originAddresses;
              var destinations = response.destinationAddresses;
              var outputDiv = document.getElementById('outputDiv');
              outputDiv.innerHTML = '';
              deleteOverlays();

              for (var i = 0; i < origins.length; i++) {
                var results = response.rows[i].elements;
                addMarker(origins[i], false);
                for (var j = 0; j < results.length; j++) {
                  addMarker(destinations[j], true);
                  outputDiv.innerHTML += origins[i] + ' to ' + destinations[j]
                      + ': ' + results[j].distance.text + ' in '
                      + results[j].duration.text + '<br>';
                }
              }
            }
          }

          function addMarker(location, isDestination) {
            var icon;
            if (isDestination) {
              icon = destinationIcon;
            } else {
              icon = originIcon;
            }
            geocoder.geocode({'address': location}, function(results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                bounds.extend(results[0].geometry.location);
                map.fitBounds(bounds);
                var marker = new google.maps.Marker({
                  map: map,
                  position: results[0].geometry.location,
                  icon: icon
                });
                markersArray.push(marker);
              } else {
                alert('Geocode was not successful for the following reason: '
                  + status);
              }
            });
          }

          function deleteOverlays() {
            if (markersArray) {
              for (i in markersArray) {
                markersArray[i].setMap(null);
              }
              markersArray.length = 0;
            }
          }

        </script>
      </head>
      <META HTTP-EQUIV="refresh" CONTENT="60">
      <body onload="initialize(), calculateDistances()">
        <div id="inputs">
          <pre class="prettyprint">
    This will automatically calculate distances on load and then will re-load every minute. hahaha...
    Really need to work out how to pull data from a fusion table as well.
          </pre>
          <p><button type="button" onclick="calculateDistances();">Force Re-Calculate
            distances</button></p>
        </div>
            <div id="outputDiv"></div>
        <div id="map"></div>
      </body>
    </html>

谢谢马特。

4

1 回答 1

0

概念证明:

http://www.geocodezip.com/v3_GoogleEx_FusionTables_latestData.html

使用 FusionTables API v1.0 查询表中的数据;为“最新”位置(时间戳列中具有最大值的位置)创建原生 Google Maps API v3 标记。

请注意,如果您有很多标记或只有标记,您可能需要修改方法。

于 2012-10-02T22:16:33.757 回答