Error: the provided value is not recognized as an array

I am having trouble with the google maps polygon function. Despite the map displaying correctly, I keep getting the error message: InvalidValueError: not an Array. Does anyone have any suggestions on how to solve this issue? Your help is much appreciated!

Below are the code snippets I am using:

Homepage.ts

import { Component, OnInit } from '@angular/core';
import { ViewChild, ElementRef } from '@angular/core';

declare var google: any;

@Component({
  selector: 'app-home',
  templateUrl: './home.page.html',
  styleUrls: ['./home.page.scss'],
})

export class HomePage implements OnInit {

  map: any;
  @ViewChild('map', { read: ElementRef, static: false }) mapRef: ElementRef;

  polygon: any = [];
  triangleCoords: any = [
    { lat: 25.774, lng: -80.190 },
    { lat: 18.466, lng: -66.118 },
    { lat: 32.321, lng: -64.757 },
    { lat: 25.774, lng: -80.190 }
  ];

  constructor() {
  }

  ionViewDidEnter() {
    this.showMap();
  }

  addPolygon(triangleCoords) {
    for (let triangleCoord of triangleCoords) {
      let bermudaTriangle = new google.maps.Polygon({
        paths: triangleCoord,
        strokeColor: '#FF0000',
        strokeOpacity: 0.8,
        strokeWeight: 2,
        fillColor: '#FF0000',
        fillOpacity: 0.35
      });
      bermudaTriangle.setMap(this.map);
    }
  }

  showMap() {
    const location = new google.maps.LatLng(24.886, -70.268);
    const options = {
      center: location,
      zoom: 5,
      disabledDefaultUI: true
    }
    this.map = new google.maps.Map(this.mapRef.nativeElement, options);
    this.addPolygon(this.triangleCoords);
  }

  ngOnInit() {
  }
}

homepage.html

<ion-header>
  <ion-toolbar>
    <ion-title>Home</ion-title>
    <ion-buttons slot="start">
      <ion-menu-button menu="main-menu"></ion-menu-button>
    </ion-buttons>
  </ion-toolbar>
</ion-header>

<ion-content [fullscreen]="true" class="ion-padding">
  <div #map id="map"></div>
</ion-content>

The error indicates that it expects an array, however, I am unsure of what needs to be added or removed.

Answer №1

triangleCoords is a unique feature of your class that can be accessed by including this:

let mysteriousTriangle = new google.maps.Polygon({
    paths: this.triangleCoord, // <<<<<<<<<<<<<<<<<<<< Fix 
    strokeColor: '#FF0000',
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: '#FF0000',
    fillOpacity: 0.35
});

In previous iterations of the code, triangleCoord was undefined within the context of the addPolygon method, leading to the error message.

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

Tips for properly formatting the bound value prior to its display while utilizing ng-model

Currently, my code looks like this: $scope.value = 0; /// <input type="number" ng-model="value" placeholder="This is not displaying" /> As you can see, the default value of 0 shows up inside the number input instead of the desired placeholder. I ...

Using Vue to Bring in External JavaScript Files

If I have 2 JavaScript files located in the 'resources/assets/js' directory, named 'app.js' and 'ext_app.js', what could be the issue? Within 'ext_app.js' file, there is a function defined like this: function testF ...

Tips for adjusting the size of an imported item in Three.js?

Currently, I am utilizing Three.js for my project and I am importing .OBJ file using OBJ LOADER () Everything has been working smoothly thus far, but I have come across an issue that has me stumped. I am trying to figure out how to change the width and he ...

When I attempt to utilize the API, the JavaScript implementation of a <script src=...> element seems to interfere

Within one of my HTML files, I encountered the following line near the top: <script src="//maps.google.com/maps/api/js?key=apikey"></script> The API key is currently hardcoded in this file, but I would like to use a configuration option store ...

Tips for configuring the default date and time in the DateTimePicker without any offset

Currently, I am encountering an issue with the MUI DateTimePicker while using a custom text input field. The problem arises when I input a date and then reopen the DateTimePicker, as it defaults to the wrong value. If you need more information or details, ...

What is the process by which a JavaScript Date object is converted to a string when you log it to the

Whenever I create objects in JavaScript and output them to the console, I typically see a JavaScript object displayed. For instance: var myObj = { bla: "foo" } console.log(myObj); This code will display: { bla: "foo" } However, whe ...

Exploring the magic of Nest.JS with the power of Observables

As a newcomer to Nest.JS, I am struggling with understanding how to effectively utilize observables. I have a method that needs to perform the following tasks: Login to HashiCorp Vault and retrieve a client_token via an HTTP call. If a token is received f ...

Are there any JS/jQuery plugins available for sliding animations that include slideLeft and slideRight functions, similar to the slideUp and slideDown functions?

Does anyone know of a jQuery/JS plugin that combines fading and sliding effects, specifically with slideLeft and slideRight functions similar to jQuery's slideUp and slideDown? I'm hoping to find something ready-made rather than having to build i ...

Angular 6 CSS spacing dilemmas

We recently made the switch from Angular 5 to Angular 6 and noticed that there is no spacing between the buttons/icons, etc. We are looking to bring back the spaces between the buttons and icons. I have recreated the issue below. As you can see in the Ang ...

The speed of Nuxt build on Mac with M1 Chip is unacceptably slow

I'm having issues with the build speed of my Nuxt project on my new M1 chip Machine(Mac). The compilation process is taking too long. I have installed nodenv into my project and I am using version v12.9.0. The package manager (npm/yarn) in the projec ...

In what way are these columns altering their layout without the use of JavaScript?

While I was searching for a solution to organize content based on screen size, I came across this website. The layout of the site changes depending on the size of the browser window. When I resize my browser or view the site on a phone, the large image at ...

Sending an array from the server to the client using Node and Express during page loading?

I am utilizing Node and Express in my project. The application fetches data from a remote database on page load and sends it to a handlebars template server-side. However, I would like this JSON data to also be accessible for client-side interactions. How ...

Having trouble installing the 'ws' npm package on MacOS Big Sur?

Every time I try to install the websocket package using "npm install ws", I keep getting this error message: npm ERR! code ENOSELF npm ERR! Refusing to install package with name "ws" under a package npm ERR! also called "ws". Did you name your project the ...

Tips for changing a property of an object in React

My object structure is as follows: booking Object { "2019-11-29": Object { "selected": true, }, "2019-11-30": Object { "selected": true, }, } I am looking to modify this object by triggering a function. Specifically, I need to toggle the ...

Prevent clicks from passing through the transparent header-div onto bootstrap buttons

I have a webpage built with AngularJS and Bootstrap. It's currently in beta and available online in (German and): teacher.scool.cool simply click on "test anmelden" navigate to the next page using the menu This webpage features a fixed transparent ...

Issue with Google Map Info Windows resizing automatically, no changes have been made to the code

Take a look at my map application. By clicking multiple times on a red marker, you will notice that the info window changes size until it becomes unusually large, affecting all other windows as well. Interestingly, previous versions of my code from 1 month ...

The file size exceeds the server's upload limit, despite making changes to the php.ini file

I've encountered a problem trying to upload an .OBJ file to the server, resulting in an 'Error 1' message. The uploaded file surpasses the upload_max_filesize directive specified in php.ini This error is detailed on this page - http://ph ...

Is it not possible to include Infinity as a number in JSON?

Recently, I encountered a frustrating issue that took an incredibly long time to troubleshoot. Through the REPL (NodeJS), I managed to replicate this problem: > o = {}; {} > JSON.stringify(o) '{}' > o.n = 10 10 > JSON.stringify(o) ...

Integrate JavaScript date into the gulp-rev workflow

I have been encountering an issue while using the gulp-rev plugin to add a revision of my app/html page generated by the Yeomann webapp generator. My workflow involves zipping the app and then adding a revision, but I am having trouble replacing the hash t ...

Specify the type of nested object exclusively with string values

I am working on creating a complex nested object structure with string values only, as shown below: let obj = { foo: "bar", foo2: "bar2", nestedFoo: { foo3: "bar3", anotherNested: { foo4: "bar4" ...