Google Maps experiencing an Uncaught Error: Maximum of 10 $digest() iterations reached. Operation aborted on Angular application

I'm currently working on integrating a map into my Angular app to display coordinates obtained from an API on a detailed page. However, I'm encountering an error in the HTML code:

Uncaught Error: 10 $digest() iterations reached. Aborting!

Here is the HTML code snippet:

<input value="{{place.place.name}}">

<label>zoom</label>
<input type="number" ng-model="zoom"/>

<div id="map_canvas">
<google-map center="{latitude: place.place.lat, longitude: place.place.lng}" zoom="zoom" draggable="true" options="options">
  <marker coords="{latitude: place.place.lat, longitude: place.place.lng}"></marker>
</google-map>

</div>

The above code snippet is causing the mentioned error. How can this issue be resolved? Below is the JavaScript code where the Controller that connects with the page containing the map is located:

$http.get('http://94.125.132.253:8000/getuncategorisedplaces').success(function (data, status, headers) {

    $scope.places = data;
    console.log(data);
    $scope.message = 'Uncategorised places';
})
$scope.id = $routeParams.id;
$scope.showplace = function(id) {
  $http({method: 'GET', url: 'http://94.125.132.253:8000/getitemdata?ID=' + $scope.id}).
      success(function(data, status, headers, config) {
          $scope.place = data;               //set view model
          console.log(data);

          console.log(id);

           $scope.view = 'templates/detail.html';

      })
      .error(function(data, status, headers, config) {
          $scope.place = data || "Request failed";
          $scope.status = status;
          $scope.view = 'templates/detail.html';
      });
   }
  $scope.showplace();


      $scope.map = function(){

 $scope.zoom = 13;


  }
$scope.map();
$scope.meta = function () {
    $http.get('http://94.125.132.253:8000/getmetas').success(function (data, status, headers) {

        $scope.metas = data;
        console.log($scope.category);
        console.log(data);
        $scope.message = 'List of Uncategorised places';


    })
}
$scope.meta();
$scope.meta1 = function (data, status, headers) {
    var formdata = {
        'cat': $scope.cat,
    }
    var inserturl = 'http://94.125.132.253:8000/getcategories?meta=' + formdata.cat;
    return $http.get(inserturl).success(function (data, status, headers) {

        $scope.categories = data;
        console.log(formdata.cat);
        console.log(data);

    });
};


$scope.$watch('cat', function (newvalue) {
    $scope.meta1();
});
$scope.meta2 = function (data, status, headers) {
    var formdata = {
        'category': $scope.category,
    }
    var inserturl = 'http://94.125.132.253:8000/getsubcategories?category=' + formdata.category;
    return $http.get(inserturl).success(function (data, status, headers) {

        $scope.subcategories = data;
        console.log(formdata.sub);
        console.log(data);

    });
};

$scope.$watch('category', function (newvalue2) {
    $scope.meta2();
});

Answer №1

It seems like your interest lies in integrating Google Maps with AngularJS.

May I suggest considering ng-map as an alternative solution, as mentioned in this Stack Overflow post.

Using ngMap can easily meet your requirements without the need to delve deep into directive options and guidelines.

<script>
var MyCtrl = function($scope) {
  $scope.updateCenter = function(lat,lng) {
    $scope.map.setCenter(new google.maps.LatLng(lat, lng));
  }
}
</script>

<body ng-controller="MyCtrl">
  <map center="[40.74, -74.18]"></map>
  <button ng-click="updateCenter(41.74, -75.18)">Update Center</button>
</body>

Check out an example here!

Answer №2

From what I can tell, your HTML code seems to be fine. The issue you are experiencing typically arises when a circular loop is created, such as updating a watched variable and then updating it again within the triggered event function.

Could you please provide us with your JavaScript code by editing your question?

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

Bootstrap Photo Loader

I am currently working on a project using a bootstrap image upload plugin. However, I have encountered an issue in my services edit page where I am unable to display auto thumbnails of previously uploaded images. When I click the upload button and select a ...

Finding the perfect pairing: How to align counters with objects?

public counter = 0; x0: any; x1: any; x2: any; x3: any; x4: any; next(){ this.counter += 1; this.storage.set("Count", this.counter); console.log(this.counter); this.logic(); } logic(){ //automatic counter here var xNum = JSON.parse(JSON.stri ...

Identify the position of a mouse click event when dots overlap

Experience this live demo on CodePen by visiting it here. 1) When you click on the grid, a first red point will be added. 2) Click on the grid again to add a second red point. 3) By clicking back on the first red point, you may notice that the coordinat ...

Building a Facebook Messenger bot using Node.js and harnessing the power of Python's Beautiful Soup for web scraping

In the process of creating a Facebook Messenger bot, I have incorporated JavaScript, NodeJS, and Heroku to develop a bot that repeats messages back to the sender. Now, I am considering using Beautiful Soup for the web scraping aspect. My question is, can ...

Having trouble retrieving JSON data from an API using jQuery's AJAX method

Currently, I am attempting to retrieve a JSON object from an API endpoint using jQuery and AJAX. Here is the code that I have been working with: $.ajax({ url: 'https://this-specific-website.com/customers.json', type: 'GET', ...

Issue: Trouble with Rotating Tooltips in Javascript

I am facing a challenge with the tooltips on my website. I want to ensure that all tooltips have a consistent look and transition effects, but I am struggling to achieve this. The rotation and other effects applied using javascript are not functioning prop ...

Tips for customizing the appearance of a single plot within a time series chart using FusionCharts or FusionTime

I've implemented a time series line graph using FusionCharts in the following code snippet: const MyChart = () => { const schema = [ { name: "Category", type: "string" }, { ...

The current URL in the browser does not change

My HTML form has a JavaScript function that involves handling the window.location.href. I successfully remove two unwanted query string parameters from the source using this function, as shown in the first and second alert screenshots. However, I encounte ...

Make your CSS and JS files smaller by using a PHP compression script in your WordPress child theme

  I am looking to implement a PHP script that will serve combined, pre-gzipped, and minified JS and CSS files. You can find the source code for this script here: https://code.google.com/p/compress/ I have a WAMP localhost with WordPress install ...

How can I stop a checkbox from being checked if the confirm box is canceled in AngularJS?

Whenever I click on a checkbox, a confirmation box pops up. When I click "OK," the checkbox gets checked, which is what I want. However, if I click "CANCEL" in the confirm box, the checkbox still gets checked. How can I prevent this from happening? Here&a ...

Click on the bootstrap carousel to dynamically load images

I am currently developing a website with numerous images, and in order to enhance loading time, I plan to have hidden images load when the user clicks on the cover image using JavaScript. Subsequently, these images will be inserted into a Bootstrap carouse ...

Prevent tab key focus in jQuery UI autocomplete

Sharing my own answer here: Here is the HTML code I am working with: <select id="genre-select"> <option value="-1">Please select</option> <option value="1">One</option> <option value="2">Two ...

Designing a dropdown menu within displaytag

I am currently utilizing displaytag to present tabular data, but I aspire to design a user interface akin to "kayak.com" where clicking on a row reveals additional details without refreshing the page. Here is an example scenario before clicking the Detail ...

When attempting a POST request with SSL to a third-party API, an error occurred stating: "The origin http://localhost:5000 is not permitted by Access-Control-Allow-Origin."

I am in the process of developing a website using AngularJS and Restangular, and I have encountered an issue while trying to make AJAX requests to a third-party webservice that utilizes an SSL certificate. Upon sending the request, I received an error 0 a ...

Using Angular and C#, learn how to efficiently incorporate functionality for saving lists, including the addition, removal, and saving of items

I am working on an application that involves managing a list of objects within a web view. Upon loading the page, an AJAX request is triggered to an ASP MVC controller. The controller utilizes Entity Framework to retrieve the list of objects from a SQL se ...

Sending empty parameter data via Ajax to an MVC controller

Initially, I had no issues passing a single parameter to my MVC Controller through Ajax. However, when I attempted to add an extra parameter, both parameters stopped sending data to the Controller. Can anyone help with this issue? Thank you! Ajax Code: ...

Optimal method for parsing URLs using ES6

There have been many remarkable inquiries regarding this topic, such as: how to parse a url. However, as time has gone by, the answers I come across are outdated. I am looking for a more modern and flexible method to parse URLs, without relying on regular ...

Discovering the functionality provided by Angular UI router to handle nested views through

I've developed a single-page application using angularjs, UI-Router, and nested views. The structure of my code is as follows: app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider' ,'$mdDateLocaleProvi ...

Can AdonisJS 4.1.0 support conditional queries?

I am exploring the capabilities of AdonisJs query builder by referring to their documentation at Currently, I am attempting to replicate a scenario similar to the one demonstrated under the 'Conditional Queries' section: const query = Database. ...

What methods does Stack Overflow use to achieve rapid execution of Ajax features on its website?

I am amazed by the lightning-fast Ajax functionality on Stack Overflow. From voting to commenting, answering, approving edits, and even editing questions and answers, everything runs so smoothly with incredible speed. In our usual scenarios, making an Ajax ...