簡體   English   中英

將樣式應用於融合表上的圖標時,獲得意外的標識符

[英]when applying styles to icons on fusion table, getting unexpected identifier

擁有我使用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);

我相信您在styles之前缺少逗號

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

您在樣式之前缺少“,”:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM