【问题标题】:when applying styles to icons on fusion table, getting unexpected identifier将样式应用于融合表上的图标时,得到意外的标识符
【发布时间】:2015-02-17 23:15:01
【问题描述】:

有一张我使用 Google Maps API 和 Fusion Tables 制作的地图。我正在尝试更改地图上标记的外观。

当我添加“样式”时,https://developers.google.com/maps/documentation/javascript/fusiontableslayer 我的地图将不会加载到页面上,并且我的控制台读取错误:“意外标识符 - 样式”

谁能帮我弄清楚我做错了什么?

这是我的代码:

var map, layer;
var geocoder;

function initialize(location) {

  console.log(location);
  geocoder = new google.maps.Geocoder();
  var userlocation = new google.maps.LatLng(location.coords.latitude, location.coords.longitude);

  map = new google.maps.Map(document.getElementById('map-canvas'), {
    center: userlocation,
    zoom: 8
  });

  layer = new google.maps.FusionTablesLayer({
    query: {
      select: '\'Geocodable address\'',
      from: '1x265dMvUClEGEVHD_3VRBvSRXk-mbs4jcO2xy29K',
    }
    styles: [
   {markerOptions:{ iconName:"star"}}
  ]                                        
  });
  layer.setMap(map);
}

function codeAddress() {
  var address = document.getElementById('address').value;
  geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.setCenter(results[0].geometry.location);
    } else {
      alert('Geocode was not successful for the following reason: ' + status);
    }
  });
}

navigator.geolocation.getCurrentPosition(initialize);

【问题讨论】:

    标签: javascript css google-maps google-maps-api-3


    【解决方案1】:

    我相信您在styles 之前缺少一个逗号

    layer = new google.maps.FusionTablesLayer({
        query: {
          select: '\'Geocodable address\'',
          from: '1x265dMvUClEGEVHD_3VRBvSRXk-mbs4jcO2xy29K',
        }, //need a comma here
        styles: [{...
    

    【讨论】:

      【解决方案2】:

      样式前缺少“,”:

      layer = new google.maps.FusionTablesLayer({
          query: {
            select: '\'Geocodable address\'',
            from: '1x265dMvUClEGEVHD_3VRBvSRXk-mbs4jcO2xy29K',
          },
          styles: [
         {markerOptions:{ iconName:"star"}}
        ]                                        
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-09-14
        • 1970-01-01
        • 2017-09-05
        • 2020-07-10
        • 2012-06-19
        • 2014-04-10
        • 2013-10-14
        相关资源
        最近更新 更多