"Implementing a feature in AngularJS to dynamically display markers on a Google Map based on latitude and

I am a newcomer to AngularJS and I am attempting to pass my JSON latitude and longitude based on ID into the Google API. Here is the structure of my JSON file:

{
 "totalCount":206,
  "deals":[{
       "id":"2",
       "Name":"samir",
       "locations":[{
         "location":"Mundhwa Gaon",
         "address":"Mundhwa Gaon, North Main Road, Pune - 411 001",
          "latLon":"18.53918870,73.90790910"
          },
          "location":"Mundhwa Gaon",
          "address":"Mundhwa Gaon, North Main Road, Pune - 411 001",
          "latLon":"18.53918870,73.90790910"
          },
        ]
      },
      "id":"3",
       "Name":"samir",
       "locations":[{
         "location":"Mundhwa Gaon",
         "address":"Mundhwa Gaon, North Main Road, Pune - 411 001",
          "latLon":"18.53918870,73.90790910"
          },
          "location":"Mundhwa Gaon",
          "address":"Mundhwa Gaon, North Main Road, Pune - 411 001",
          "latLon":"18.53918870,73.90790910"
          },
        ] 
   }]
}

Here is my AngularJS code:

$http({method: 'GET', url: '/api/v1/asas}).success(function(data) {             
            $scope.deal = data.deals;               


if(data.deals[0].hasOwnProperty("locations") && data.deals[0].locations!=null){                         
                var location=$scope.deal[0].locations[0]['latLon'];
                var locationlatlong=location.split(",");
                $scope.map = {center: {latitude: locationlatlong[0], longitude: locationlatlong[1] }, zoom: 4 }
                $scope.options = {scrollwheel: false};
                var markers = [];
                for (var i = 0; i < $scope.deal[0].locations.length; i++) {
                    markers.push(createmarker(i, $scope.deal[0].locations[i]['location'], $scope.deal[0].locations[i]['latLon'],$scope.deal[0].locations[i]['address']))
                }
                $scope.markers = markers;
                if(badBrowser){
                    $scope.rendermap=false; 

                }else{                      
                    $scope.rendermap=true;      

                }
            }                       


        });

Currently, it only passes the location of the first deal ID. I am trying to implement a functionality where clicking on a deal will pass that deal's ID location (latitude and longitude). My AngularJS version is 1.2.23.

Answer №1

From my observation, it appears that using $scope.deal.locations.length; in the for loop is more appropriate than $scope.deal[0].locations.length;

However, it would greatly improve the ability to assist you if you could provide a JSFiddle with your issue.

Answer №2

Resolved the issue with my code

$scope.mapcall = function (deals) { 
        $scope.rendermap=false; 
        $scope.rendermapbtn=false;              
        if(deals.locations!=null){                  
            $scope.rendermapbtn=true;                                   
            var location=deals.locations[0]['latLon'];
            var locationlatlong=location.split(",");
            $scope.map = {center: {latitude: locationlatlong[0], longitude: locationlatlong[1] }, zoom: 4 }
            $scope.options = {scrollwheel: false};
            var markers = [];
            for (var i = 0; i < deals.locations.length; i++) {
                markers.push(createmarker(i, deals.locations[i]['location'], deals.locations[i]['latLon'],deals.locations[i]['address']))
            }
            $scope.markers = markers;
            if(badBrowser){
                $scope.rendermapbtn=false;

            }else{                      
                $scope.rendermapbtn=true;   

            }
        }       
    };  

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

What are the steps for transmitting an array of data to Parse Cloud Code?

Trying to send an array of contact emails as a parameter in Cloud Code function for Parse, here is how I am doing it: HashMap<String, ArrayList<String>> params = new HashMap<>(); ArrayList<String> array = new ArrayList<>(); a ...

Is it possible to capture user input using a rich text editor such as Quill and save the data as a .json file by sending a POST request?

My website features a sophisticated text editor known as ngx-quill, where users can input their content. I am currently working on a project that requires me to generate a JSON file containing user input and then submit this JSON file. I am seeking guidan ...

Creating an interactive Table of Contents in Sharepoint using only JavaScript

Imagine you have a massive Sharepoint wiki page filled with various heading tags like H1, H2, H3, and H4 - now picture creating a dynamic Table of Contents using these tags. The goal is to categorize these tags by group and utilize the HTML <detail> ...

Develop a jQuery dialog box without assigning an ID

I need help with jQuery to create a dialog that opens and then populates with values. When I tried to create the dialog using jQuery, it kept using old values because the div already existed on the page. I want to create a new instance of the dialog usin ...

Struggling to consume a RESTful API in Java using the HTTPClient library. Currently facing difficulties with handling a Jackson JSON Mismatch

I am new to using Jackson and consuming APIs with HttpClient. I encountered the error com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.util.ArrayList<WallHaven> from Object value (token JsonToken.STAR ...

AssertionError [ERR_ASSERTION]: The value of undefined is not equal to 390 in the GitLab

I'm a bit confused about the AssertionError [ERR_ASSERTION]: undefined == 390 in Gitlab. What I need is: The sumSalaries(obj) function, which should take an object obj as a parameter where the field names correspond to the employee's name and t ...

Simple method for securing and unsecuring uploaded files in a directory with the use of AngularJS and a PHP framework

I've been exploring options for encrypting and decrypting files, specifically .pdf files. After researching and experimenting with codes like crypto.js, I'm still struggling to grasp the process. Can someone provide guidance on how to achieve thi ...

The alignment of the JQuery Mobile tabs is off

As I work on developing a Cordova app, I've noticed that the tabs on my Android phone display in an unusual way. Here's what they look like: The image above was created in JSFiddle using JQuery 2.1.0 and JQM 1.4.2 selected with the following co ...

How can Angular JS handle multiple validators being triggered at once?

Hey there, I'm currently working with validators in my Angular form setup. Here's a snippet of how it looks - I utilize Validators.compose to combine custom validators. The errors from these validators are then displayed on the HTML component. My ...

Bootstrap's square-shaped columns

I would like to implement a grid of squares for navigation purposes. By squares, I mean that the colored areas should have equal width and height. Currently, I have achieved this using JavaScript, but I am interested in a CSS-only solution. My project is ...

Organizing items into categories using a two-dimensional array with jQuery

My goal is to organize my items by category, displaying them as follows: Category A Item 1 Item 2 Category B Item 1 Item 3 Item 4 Category C Item 3 Item 4 I have an array that contains the necessary data. How can I efficiently print the categori ...

Find the correct file path for input using JavaScript or Angular 2

How can I retrieve the full file path of a selected Excel file using either pure JavaScript or Angular 2? I am looking to have the user select an Excel file, which will then be sent to a C# WEB API controller for further processing. Currently, my setup is ...

Struggling to incorporate z-index for a tooltip component that overlaps in a project utilizing React, Tailwind, and DaisyUI

Hello everyone, I trust you are all doing great. I have a query regarding a Fireship IO tutorial on incorporating TailwindCSS and DaisyUI into React. I've managed to create a side navbar similar to Discord, complete with tooltips that display as span ...

Utilize JSON API data in Laravel or integrate it into an iOS application

I am utilizing Laravel fractal for transforming my API data. Within my database, there exists a timestamp such as "2015-02-15 14:34". However, I wish to transform this into "Time remaining" instead of just displaying the timestamp. For example, "2015-03- ...

How can I convert deeply nested JSON data into a dataframe in R (or an alternative tool)?

Trying to parse multiple JSON files on a dataframe in R proved to be quite challenging for me. Some of the files were straightforward and easy to parse using the jsonlite library, while others were deeply nested and presented significant challenges. Despi ...

Incomplete data retrieval issue encountered during .ajax call

I am having trouble retrieving all 4 key|value pairs from a page that displays an object as text in the body and pre tag. It seems to be missing one pair - any ideas why? Just a heads up, I've tweaked some of the URLs and data in the JSON output for ...

Suggestions for incrementing a button's ID every time it is clicked

I am working on a button functionality that increases the button id when clicked. Below is the HTML code for the button: <input type="button" id="repeataddon-1" name="repeataddon" class="repeataddon" value="add" > Accompanied by the following scr ...

Retrieving a time series data set from a JSON stream

Even though ThingSpeak offers great charts, I'm interested in retrieving data from ThingSpeak and creating my own visualizations using Google Charts. When extracting a "feed" from ThingSpeak, the data is presented in a JSON object like the one below: ...

I am struggling to comprehend the code for a PHP form that triggers a JS OnUpdate event, which then uses AJAX to retrieve data from MySQLi

I want to give a special thanks to Alon Alexander for providing the JS and AJAX code, even though I don't fully comprehend it. I am more comfortable using PHP/JS without jQuery, but I am struggling to make it function as intended. My current issue in ...

The click event is activated following the :active selector being triggered

My Angular application features a button with a slight animation - it moves down by a few pixels when clicked on: &:active { margin: 15px 0 0 0; } The button also has a (click)="myFunction()" event listener attached to it. A common issue arises w ...