Tips for minimizing the number of map calls in an Angular Web App using agm-core

Our team has developed a user-friendly application using Angular with 5 pages, each featuring a Google map. The main reason for choosing Angular was to minimize the number of Map calls per user session to just 1; previously in our javascript-based app, this number was as high as 20 per session!

Despite our efforts, the current implementation still results in multiple map calls corresponding to the number of visits to each page. We are seeking guidance on where we may have gone wrong.

Here is how our setup looks:

  • We utilize the agm-core library (instead of JS script directly) and segment our app into 5 sub-components (each representing a page) with a master component: /home. The map is imported in a separate component at the same level as Home component

  • We provide users with an option to hide the map by either setting map height/width to zero or moving the map off-screen and bringing it back when needed.

Component structure:

- map-div
- home
  - page1
  - page2
  - page3
  - page4
  - page5

Although clicking on different pages should not trigger reinitialization of map-div, our testing reveals that each page click still contributes to additional Map calls, as observed in GCP API logs.

Note: For assessing API call counts, we set up a distinct environment with a new key and meticulously tracked steps taken to determine the accurate count. Every click on Pages 1...5 registered as a unique API call.

Below details the usage displayed under GCP API/Services -> Credentials -> Key after engaging with pages 1 to 5, totaling 12 interactions.

Total usage (last 30 days)
12

We confirmed the transaction data in Billing, which reflects the charges for Dynamic Map calls accurately.

While we haven't delved deep into the code within agm-core yet, we aim to avoid creating a custom JavaScript class to tackle this issue. Any suggestions on a more efficient approach would be deeply appreciated. Feel free to request more details or code snippets if required.

How can we modify our approach to ensure that each session incurs only 1 map load?

Thank you

Answer №1

It is not possible to design it so that a single user session only requires one map load. The JavaScript API used by the agm-core library does not offer session-based or caching options.

A map load refers to each instance where a map is created using the google.maps.Map() class. Even if the map is "hidden," creating it still counts as a load. Every time a web page refreshes and loads a map, it adds to the total count. Therefore, every visit to a page will increase the number of map loads, regardless of whether it's within the same user session.

If you wish to reduce costs, aside from eliminating unnecessary map displays on certain web pages, I suggest exploring daily quota limits and budget alerts outlined in this FAQ.

Answer №2

Sharing our unique resolution in case it benefits others.

Bypassing the limitations of agm-core maps class, we innovatively crafted a personalized class utilizing Google Maps Javascript.

This approach streamlines map requests, restricting them to a single instance per user session across all pages within our web application.

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

Determining Marker Location Post Drag in Laravel-VUE Component

I have integrated vue-google-maps into my project and it is working well so far. My goal is to have a marker appear when a user searches and selects their area, and then they can drag the marker to the desired position. I have successfully made the marker ...

Capacitor-enabled Ionic Audio Recording

Finally completed my chat app, but I am looking to enhance the voice messaging feature to be more in line with Messenger rather than a standard file.wav format. Any suggestions or ideas would be greatly appreciated! https://i.stack.imgur.com/soXZC.png Cu ...

Error handling: Encountered unexpected issues while parsing templates in Angular 2

I'm a beginner with Angular 2 and I'm attempting to create a simple module, but encountering an error. app.component.html import { Component } from '@angular/core'; import { Timer } from '../app/modules/timer'; @Component({ ...

Discover how to retrieve service response data from an API and populate it into the Select Option with Angular 2

Api.services.ts getListOfNames() { return this.http.get(this.BaseURL + 'welcome/getnama') .pipe(map(response => { return response; })); } After making the API call, I receive the following resp ...

What is the best way to utilize ngStyle in combination with Interpolation?

Within my application, I am faced with a challenge involving two slide bars that generate values ranging from 1 to 100. Based on these generated values, I aim to adjust the margin of a div element in accordance with the percentage output. Despite conductin ...

Retrieve HTTP status code within Angular 2 component from a Service

I encountered an issue while trying to return an object from my Http Service's catch block to my component: Below is the code snippet from my service: login(username,password){ let headers = new Headers(); headers.append('Conten ...

Navigating an angular collection like a pro

I have the following example data structure within a Component: const Questions = { "java": [ {text: "Is this a question?", answer: "Yes"}, {text: "Another question", answer: "Yes"} ], "python": [ {text: "A different qu ...

There was an unexpected error: The development server's address information is not defined

Whenever I attempt to utilize ng serve with SSL and a custom hostname, I encounter the error message "An unhandled exception occurred: Dev-server address info is not defined." Has anyone found a solution to this issue? Here is the command I am using: ng s ...

Angular: Dynamically add or delete an interceptor based on conditions

Is it possible to dynamically include or exclude an interceptor based on user selection? For my application, I want to enable Azure AD based SSO using the @azure/msal-angular package https://www.npmjs.com/package/@azure/msal-angular that provides an inter ...

"Enhancing User Experience with Angular 2: Customizing Component Selection and Sty

I am currently working on an Angular application that fetches a configuration file in .json format. My goal is to dynamically choose components and apply inline styles to them. Below is an example of the structure of the configuration data obtained from a ...

The issue encountered during the construction of the nrwl library project is that object Object is not recognized as a PostCSS

We are currently facing an issue with our nrwl-nx workspace library project (based on Angular 8) that contains 3-4 angular libraries. While the ng serve function works properly, we have started encountering errors when trying to run ng build my-lib. On ou ...

Converting JSON HTTP response to an Array in AngularJS 2: A Comprehensive Guide

As I work on a Http get request in Angular 2, the response returned is in JSON format. However, I am facing an issue when trying to use it in a ngFor loop because it is not formatted as an Array. Is there a way to convert JSON data to an Array in Angular ...

Steps for setting up the 'node_modules' folder in an older Angular project using the 'npm install' command

Currently, I am in the process of transferring our project code from our repository to a new laptop. The project was initially developed on Angular 5 last year. However, the new laptop is equipped with the latest versions of Angular CLI, NodeJS, and NPM to ...

What is the purpose of declaring data types such as string, number, boolean, void, and others in Angular 2

I'm curious as to why programmers declare classes in individual scope or something. For example, take a look at this code snippet: result: boolean = false public generateRand(x): void { } This is also similar to the following: result = false publi ...

Google Maps API now offers the ability to generate directions with up to 500 waypoints

I am facing a challenge with displaying a route on Google Maps using an array of 500 waypoints extracted from a GPS route. Google Maps is unable to create a direction or route with more than 23 waypoints, making it difficult to replicate the original GPS ...

Position components in Angular 2 based on an array's values

Hello all, I am a beginner in terms of Angular 2 and currently facing some obstacles. My goal is to create a board for a board game called Reversi, which has a similar layout to chess but with mono-color pieces. In order to store the necessary information, ...

Using the map operator in an Angular 7 application with rxjs

Despite successfully compiling my code and having everything work perfectly, I encountered an error message in my IDE (Visual Studio Code) that is preventing me from deploying my app using ng build --prod: ERROR in src/app/training/training.service.ts(6 ...

Is there a way to assign a value to an Angular-specific variable using PHP?

In the development of my Angular 4 application, I encountered an issue while receiving JSON data based on an id value through a PHP script. Upon examining the code, it seems that there should be a value passed into this.PropertiesList. examineProperties(i ...

How can I create a customized scrollbar for a div element in an Angular 2.0 CLI project?

I am attempting to create a sleek horizontal scroll bar within one of my div elements, similar to the example shown here: https://i.stack.imgur.com/ziWhi.png My project is based on the angular2 CLI. Progress so far: I came across this package angular2-s ...

Is it possible for me to create an HTML script that can transfer data from the script to a cell within Qubole?

Is it possible to create an HTML script that allows user interaction, pass the data back to a zeppelin cell, and trigger a rerun of the data? Thank you! Update: I have made some progress in rerunning the cell with an HTML click. The cell I want to rerun ...