Error: setPosition function only accepts values of type LatLng or LatLngLiteral. The property 'lat' must be a numerical value in agm-core agm-overlay

Currently, I am utilizing Angular Maps powered by Google @agm-core and agm-overlay to implement custom markers. However, when using the (boundsChange) function on the agm-map component, an error occurs with the message "invalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number".

Interestingly, this error only arises when attempting to use a custom marker for displaying additional information.

In order to fetch relevant data from my database based on the bounds of the map, I execute a query which returns an array of 'almacenes'.

Within my function:

doSomething2(e) {
fetch(`${this.conexion}/api/instalaciones/bounds/${e.ka.h}/${e.ka.g}/${e.oa.h}/${e.oa.g}`)
  .then(response => {
    return response.json()
  }).then(respuesta => {
    console.log(respuesta)
    this.almacenes=respuesta.content
  })
}

The content included in map.component.html goes as follows:

<agm-map [zoom]="12" [latitude]="lat" [longitude]="lng" (boundsChange)="doSomething2($event)">
    <agm-overlay *ngFor="let almacen of almacenes;let i=index" [latitude]="almacen.latitudInstalacion"
        [longitude]="almacen.longitudInstalacion">
        <div class="block">
            <strong style="color:white;">{{almacen.idInstalacion}}</strong>
        </div>
        <agm-info-window>Info Window {{i}}</agm-info-window>
    </agm-overlay>
</agm-map>

However, upon execution, there is still an occurrence of the error described earlier stating "invalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number", alongside issues with the functionality of agm-info-window.

Answer №1

agm-info-window is not a child of agm-map, but an independent directive.

<agm-map [zoom]="12" [latitude]="lat" [longitude]="lng" (boundsChange)="doSomething2($event)">
    <agm-overlay *ngFor="let almacen of almacenes;let i=index" [latitude]="almacen.latitudInstalacion"
        [longitude]="almacen.longitudInstalacion">
        <div class="block">
            <strong style="color:white;">{{almacen.idInstalacion}}</strong>
        </div>
    </agm-overlay>
    <agm-info-window *ngFor="let almacen of almacenes;let i=index">Info Window {{i}}</agm-info-window>
</agm-map>

To optimize performance by avoiding redundant ngFor loops for info window and overlay from the same array, we can combine them under a common ng-container parent:

<agm-map [zoom]="12" [latitude]="lat" [longitude]="lng" (boundsChange)="doSomething2($event)">
  <ng-container *ngFor="let almacen of almacenes;let i=index" >
    <agm-overlay [latitude]="almacen.latitudInstalacion"
        [longitude]="almacen.longitudInstalacion">
        <div class="block">
            <strong style="color:white;">{{almacen.idInstalacion}}</strong>
        </div>
    </agm-overlay>
    <agm-info-window>Info Window {{i}}</agm-info-window>
  </ng-container>
</agm-map>

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

The TypeScriptLab.ts file is generating an error message at line 23, character 28, where it is expecting a comma

I am attempting to convert a ts file to a js file. My goal is to enter some numbers into a textarea, and then calculate the average of those numbers. However, I encountered an error: TypeScriptLab.ts(23,28): error TS1005: ',' expected. I have in ...

How the addition of a type union allows it to be assigned to AnyAction

Struggling with Redux code, I've encountered a peculiar behavior regarding type assignment that has left me puzzled. In the following code snippet, it's clear that you cannot assign anyaction to iaction. Yet, surprisingly, assigning anyaction to ...

Is it possible for us to customize the angular material chip design to be in a rectangular shape

I recently implemented angular material chips as tags, but I was wondering if it's possible to customize the default circular design to a rectangle using CSS? ...

Acquiring the markers, however the latitude and longitude are both null - vue.js

I have been working on displaying markers on a map. When I fetched the data, everything seemed fine in Vue DevTools. The `this.markers` property also contains the data. However, to my surprise, the values for `lat` and `lng` inside the markers are showing ...

Using VueJS Single File Components can cause issues with the example code for "Custom Popups" in the Google Maps API

Trying to implement a unique Google Maps popup following the provided documentation. After copying and pasting the official Google example code into a VueJS jsFiddle, the custom marker functions correctly as intended. It remains in the designated area eve ...

Using Typescript and react-redux with a Stateful Component: The parameter type 'typeof MyClass' does not match the expected component type

I've been trying to dive into the world of Typescript, React, and Redux. However, I've hit a roadblock at the moment. This is the error I encountered: ./src/containers/Hello.tsx [tsl] ERROR in /home/marc/Development/TypeScript-React-Starte ...

Get ready for 10 AM with the RxJS timer function

I am trying to figure out how to schedule a method in my code using rxjs/timer. Specifically, I want the method to run at precisely 10 AM after an initial delay of 1 minute. However, my current implementation is running every 2 minutes after a 1-minute d ...

Guide to transmitting a "token" to an "API" using "React"

As a novice developer, I am facing a challenge. When users log in to our website, a JWT is created. I need to then pass this token to the API on button click. If the backend call is successful, the API response should be displayed. If not, it should show ...

How can a button click function be triggered in another component?

These are the three components in my dashboard.html <top-nav></top-nav> <sidebar-cmp></sidebar-cmp> <section class="main-container" [ngClass]="{sidebarPushRight: isActive}"> <router-outlet></router-outlet> & ...

Fake AxiosInstance. In need of obtaining response in a single test

In my api.ts file import axios from 'axios' export const api = axios.create({ baseURL: 'http://localhost:3333/', }) Within my react-page.spec.tsx file: import React from 'react' import '@testing-library/jest-dom&apo ...

Leveraging the power of mat-option and mat-radio-button within a mat-select or mat-selection-list

I'm currently working on a unique form element that combines checkboxes and radio buttons to create a multi-level selection feature. For instance, you can use it to configure properties for a car where a radio option (Digital or FM) is dependent on t ...

Issue with Angular FormControl/FormBuilder not selecting options in Select dropdown

I am creating a form to edit some items and include a Select element with options loaded from a database. However, even though I set up the name and description correctly using formBuilder/control in the component, the correct "category" is not being selec ...

Count the number of checked checkboxes by looping through ngFor in Angular

My ngFor loop generates a series of checkboxes based on the X number of items in childrenList: <div *ngFor="let child of childrenList; let indice=index"> <p-checkbox label="{{child.firstname}} {{child.lastname}}" binary=&qu ...

Calculating the length of time based on a specific date in Angular 2+: A step-by-step

API: { data:{ "duration": 12, "startDate": "27-01-2020 16:09" } } I am currently working with Angular 2+. In the API response, the duration is set to 12 (in months) and the start date is provided as well... Task at hand: My goal is to ...

refreshing the webpage's content following the completion of an asynchronous request

I am working on an Ionic2 app that utilizes the SideMenu template. On the rootPage, I have the following code: export class HomePage { products: any = []; constructor(public navCtrl: NavController, public navParams: NavParams, private woo: WooCommer ...

after ajax post, enhance original object by merging with the latest server values

After making a call to the server and successfully saving some data, I need to update the JSON array object that I have with new values. Here is a snippet of my code: [ { "id": 1, "uuid": "ce54acea-db20-4716-bceb-2f3deb1b2b86", "name": null, ...

Retrieve files by utilizing the find() function in couchdb-nano

As CouchDB doesn't have collections, I decided to add a custom type property to my entities. Now, I want to filter all the entities based on that property, for example, retrieve all users with {type:'user'}. In the CouchDB documentation, I c ...

Establish a comprehensive background for your Angular project

I've been struggling to figure out how to set a background image for my entire angular project. I've tried using global css and the app.component.css file, but it only sets the background for the component area. Here is a snippet from my global ...

What causes the headers object to become empty when Angular processes an HTTP error?

Whenever my API (.Net Core) sends a response, it includes a correlation id header to track each interaction uniquely. This process is managed at the beginning and end of the pipeline to ensure accurate identification. If there's an exception in my app ...

Encountering an issue while constructing an Angular library project. The 'ng serve' command runs smoothly on local environment, but an error message stating

I recently developed an npm package called Cloudee. While it functions perfectly locally, I encounter an issue when attempting to deploy it. The error message states: 'Unexpected value 'CloudyModule in /home/hadi/dev/rickithadi/node_modules/cloud ...