Filtering Gmaps markers using angular and javascript: A step-by-step guide

This code is designed to show markers on a map based on selected dates. Only the markers created during the chosen time period will be visible.

I am monitoring a value from an external JavaScript script called obj.dateRangeSlider("values").

as shown below;

//this function watches for changes in the time slider values and updates $scope.filteredMarks accordingly. It can also be expanded to include a search bar.
$scope.$watch(function () {
    return obj.dateRangeSlider("values");
}, function (newValue, oldValue) {
    $scope.filteredMarks = $filter("filter")($scope.marks, function(value, index){
        if(value.date >= newValue.min && value.date <= newValue.max){
            return true;
        }
        return false;
    });
});

The filtered marks are then displayed on the webpage like so;

<ui-gmap-google-map center='map.center' zoom='map.zoom' ng-init="lat = 'observation_latitude'">

    <ui-gmap-markers models="filteredMarks" coords="'self'" icon="'icon'" fit="true">
    </ui-gmap-markers>

</ui-gmap-google-map>

However, I am encountering this error multiple times;

Error: [$rootScope:infdig] http://errors.angularjs.org/1.2.20/$rootScope/infdig?p0=10&p1=%5B%5B%22fn%3…return%20m%3Da%7D%3B%20newVal%3A%20%5B%5D%3B%20oldVal%3A%20%5B%5D%22%5D%5D
    at Error (native)
    at http://localhost:56499/Scripts/Angular/angular.min.js:6:450
    at k.$digest (http://localhost:56499/Scripts/Angular/angular.min.js:110:38)
    at k.$apply (http://localhost:56499/Scripts/Angular/angular.min.js:112:173)
    at h (http://localhost:56499/Scripts/Angular/angular.min.js:72:454)
    at w (http://localhost:56499/Scripts/Angular/angular.min.js:77:347)
    at XMLHttpRequest.z.onreadystatechange (http://localhost:56499/Scripts/Angular/angular.min.js:78:420)

Returned from $scope.marks:

>     [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
>     
>     0: Object   
>     date: "2014-11-30T23:21:44.823Z"  
>     id: 11  
>     latitude: -27.46009230397052
>     longitude: 153.0309266845481  
>     __proto__:  Object  
>     Object1:  
>     Object2:  
>     Object3:  
>     __proto__: Array[0]

I am unsure of the cause of this issue and would appreciate any hints or suggestions. More information can be provided if needed.

Thank you, Sean

Answer №1

It appears that the error you are encountering is originating from

return obj.dateRangeSlider("values");

Instead of executing obj.dateRangeSlider() within the watch function, move it outside and return the variable containing the object. For more detailed information, please refer to this link. Hopefully, this has provided you with some helpful insight.

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

Slate Map by Google Navigation

I have a situation here that is similar to the grey maps, except all the buttons are visible. Everything appears normal except for the Map tiles, which are all grey! It's strange because it loads nicely at zoom level 8 and then zooms in to the maximum ...

JS seems to kick in only after a couple of page refreshes

I'm facing an issue with my 3 columns that should have equal heights. I've implemented some JavaScript to achieve this, which you can see in action through the DEMO link below. <script> $(document).foundation(); </script> <scri ...

There are currently no articles found that match the search query

Recently, I started working with Django, but I am facing an issue with slug. Whenever I send a request to the Slug, I encounter an error. The error message I receive is: Articles matching query does not exist. Furthermore, I am facing another error while ...

Implementing conditional statements using jQuery for multiple selections

Having two unique IDs, I am planning to set a condition that corresponds with my query. $("#foo", "#bar").foo.bar({ baz: function() { if(selector == "#foo") { console.log("foo"); } else { console.log("bar"); } } }); ...

What is causing an empty box to appear due to padding? Is there a way to conceal it

There seems to be an issue with adding padding to the results id div box. The padding is causing a blank yellow box to appear at the bottom before any results are submitted. I've tried to hide this box without success by adding a displayResult() funct ...

Error: The file 'templates.js' cannot be found or accessed by gulp-angular-templatecache. Please check the file path and make sure it

I have set up a basic structure for creating angular templates using Gulp. Here is the code snippet from my gulpfile: var gulp = require("gulp"), templateCache = require('gulp-angular-templatecache'); gulp.task("tc", function() { retur ...

Expanding list selection with jQuery_hover effect

I have devised the following code. HTML <ul class="treatment-menu"> <li>Menu always visible</li> <ul class="nav-child"> <li>Hidden sub menu</li> </ul> </ul> Hover function $(&a ...

Unlocking the power of styling tags in React.js

To modify the background color based on the page width, we need to have access to the styles in order to conditionally write the code. If we were to accomplish this using JavaScript, the code would look like: document.getElementById("number1").style.ba ...

Steps to retrieve the latest value of a specific cell within the Material UI Data Grid

After updating the cell within the data grid, I encountered an issue where I could retrieve the ID and field using the prop selectedCellParams, but retrieving the modified value was proving to be challenging. In order to successfully execute the PUT reque ...

Is there a way to enlarge the font size for a complete tag?

I'm having trouble with a project. One of the tasks is to use jQuery or JavaScript to increase the font size of a paragraph. The console statements are incrementing by +1 with every mouse click (the first click adds 1, the second adds 2, and so on). ...

Enhancing elements with fade-in effects upon hovering

Is there a way to incorporate a subtle fade in/fade out effect when hovering over items on this webpage: http://jsfiddle.net/7vKFN/ I'm curious about the best approach to achieve this using jQuery. var $container = $("#color-container"), ...

The disappearance of the checkbox is not occurring when the text three is moved before the input tag

When I move text three before the input tag, the checkbox does not disappear when clicked for the third time. However, if I keep text three after the input tag, it works fine. Do you have any suggestions on how to fix this issue? I have included my code be ...

What is the best way to enlarge an image on a webpage so that it is twice its original size?

I have a photo that is 320 x 240 pixels in size, and I want to enlarge it to 640 x 480 pixels when displaying it on a webpage. In the past, I used to achieve this by setting width=640 on the img tag. However, recently I came across the following informati ...

Error in jQuery sortable function occurs when dragging multiple elements

When using the sortable() function on multiple lists, I encountered a persistent bug. To drag more than one item, I added the following code to the start function: e.item.siblings(".selected").appendTo(e.item); However, a new issue arose where the plac ...

Working through JSON arrays in JavaScript

Here is a JSON example: var user = {"id": "1", "name": "Emily"} If I select "Emily," how can I retrieve the value "1"? I attempted the following code snippet: for (key in user) { if (user.hasOwnProperty(key)) { console.log(key + " = " + use ...

Advancements in ajax during the simultaneous uploading of multiple files

Hey there, I'm encountering an issue while trying to upload multiple files. The progress bar shows 100% when a small file is uploaded first, then it goes back to the correct percentage for the larger file. How can I ensure that the progress remains ac ...

What is the best way to sequentially invoke an asynchronous function within an Observable method?

Presently, I have the following method: public classMethod( payload: Payload, ): Observable<Result> { const { targetProp } = payload; let target; return this.secondClass.secondClassMethod({ targetProp }).pipe( delayWhen(() ...

Is it possible to alter objects through the use of jQuery.map?

I'm working with a key-value pair that looks like this: var classes = { red: 'Red', green: 'Green' }; Is there a way to add a specific value before each key in the pair? Can jQuery.map help with this task? The desired end result ...

Is there a JavaScript function available to remove comments from previously commented HTML code?

<div id="div1">bar</div> JQuery function addComment(element){ element.wrap(function() { return '<!--' + this.outerHTML + '"-->'; }); } addComment($('#div1')); Looking for assistance in unc ...

Create a dynamic animation of an image expanding and shifting towards the center of its parent container

Is it possible to animate an SVG image within a div to grow to 80% screen height and move to the center of the parent div when a specific function is called? If so, how can this be achieved? function openNav(){ $("#topnav").animate({height:'100%& ...