Encountering an unexpected identifier when trying to apply styles to icons in Fusion Table

I have created a map using Google Maps API and Fusion Tables, but I am struggling to customize the appearance of the markers on the map.

Whenever I try to add the "styles" as mentioned in this documentation, my map fails to load and I receive an error message stating: "unexpected identifier - styles"

Could someone please help me identify what I am doing wrong?

Below is the code snippet I am working with:

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);

Answer №1

It appears that a comma is missing before the styles section.

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

Answer №2

Ensure to include a "," before defining styles:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating personalized widths for bootstrap classes with SASS

I am interested in enhancing the bootstrap source code by creating additional w-XX classes. Specifically, I aim to include both w-40 and w-60. According to the documentation, modifying the $sizes variable is necessary for this customization. In my custom. ...

What is the best approach to get a successful response from an asynchronous method in Express?

Still grappling with the concept of Node's non-blocking nature. The code below executes as expected, but I'm curious if there's a more efficient way to achieve the same result. The route is taking 3 parameters (zipcode, type, rad) and using ...

Issues with CSS positioning

I'm facing an issue with the jQuery drop-down bar slipping behind images on a specific page that uses jQuery innerfade. You can see the problem here: <?php include('perch/runtime.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...

Preventing Multiple Form Submissions in JavaScript

I'm having an issue with my form submission to Parse where, after adding client-side validation, the data is being double submitted to the database. Despite adjusting my code based on other Stack posts and being new to JavaScript, I'm still expe ...

What steps can be taken to avoid my Bootstrap banner wrapping to a new line?

I am facing an issue while designing a top banner using Bootstrap. The condensed menu always wraps to a new line for the resolution of 1024x768. It works fine for resolutions greater than 1024x768. I need help with correcting my HTML so that the banner rem ...

Tips for navigating through a div with an unknown height

I am currently working on developing a sleek messaging system and I have encountered an issue with the interface design. My project is built using Materialize, however, I am open to tweaking it with custom CSS if necessary. The layout consists of a list of ...

What is the process for adjusting the width of an element using JavaScript?

I have a unique bar with one half red and the other green. I am trying to subtract 1vw from the width of the red section. Unfortunately, using style.width is not yielding the desired result. See below for the code snippet I am currently using: //FIGHT do ...

How can JavaScript be used to deactivate an HTML form element?

Within this form, there are two selection buttons that require client-side validation. The user must choose one of them, and once a selection is made, the other button should automatically be disabled. Below is the script I have implemented: <html> ...

Learn how to dynamically clear and update source data in jQuery autocomplete for enhanced functionality

Here is a snippet of my jQuery code. In this code, 'year' refers to the form input tag ID, and 'years' is an array variable containing all the year values. I have set this array as the source for autocomplete, which works fine. However, ...

Is it possible to show a div when a hyperlink is clicked, and then hide it when clicked again? Can this action be repeated multiple times?

Is there a way to make a div appear when a user clicks a hyperlink, and then disappear when clicked again? Currently, the div remains visible even after clicking the hyperlink multiple times. Here is an example: HTML <a onclick="showDiv()" id="ShowAbo ...

Issues with jquery gui elements in Chrome extension being unresponsive

Using chrome extensions and jquery to create a customized GUI, but running into issues with displaying the jquery elements on the HTML page. Can anyone spot what might be the problem? manifest.json: { "name": "my extension", "description": "my first ...

Using Angular JS services and controllers in separate files may result in errors

Within my angularjs project, I manage the following files: /index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-wid ...

Discovering an HTML Element in a JavaScript Array with Specific Styling: A Step-by-Step Guide

I am in the process of developing a website that consists of different sections. The concept is simple - by clicking on a button located at the bottom of the page, it will reveal the corresponding div section. For styling purposes, I have initially hidden ...

Responsive Bootstrap column with a fixed-width card

My Bootstrap-card is currently not adjusting its width properly. I want the card to occupy the full width of the column it's in. Below is a snippet of my code and a screenshot showing the current width along with the desired width indicated by a blue ...

What is the process for integrating Android Java code with Node.js code?

I have some code that I am trying to integrate with Node.js for Firebase notifications on my Android application. I found a blog post outlining the implementation here: The Node.js code listens to changes in my Firebase Database and triggers notifications ...

Is it possible to send an HTTP request from the renderer process to the main process in Electron?

Currently, I am in the midst of developing an electron video player project. My main objective is to stream video from a readable stream to an HTML video-tag. I am exploring different solutions and strategies to achieve this goal. In particular, I am cur ...

Avoiding the duplication of hidden rows in Jquery is essential

My current issue involves a table with a button to delete rows and a copy option. The problem I'm facing is that after removing a row, the copy button still copies the removed row, which is not intended. You can test the code snippet for a demonstrati ...

Creating PDFs with Vue.js from HTML sources

Looking for a way to generate PDFs and insert variable values in specific locations for an order confirmation on my website. Planning to store the generated PDFs on Firebase Storage. Any suggestions on libraries or methods to achieve this? Is it possible ...

Steps for removing every image from a folder

I'm currently facing an issue trying to remove all images from a directory. I'm encountering an error with the directory path and unsure of how to access and delete all image paths. Here is the structure of my directory : server -> app.js ...

Is it permissible to have multiple class tags in HTML?

Is the HTML code below correctly formatted? <div class="navbar" class="menu">foo</div> Can two classes be applied to the same element? ...