Why is AngularJS displaying the markers instead of the routes on Google Maps?

I placed my marker on the map and expected to see connecting routes between them, but only the markers are visible without any routes. This is quite confusing.

var cities = [
              {
                  place : 'Universal Studio',
                  desc : 'A place full of fun',
                  lat : 34.135557,
                  long : -118.354639
              },
              {
                  place : 'Beverly Hill',
                  desc : 'Shopping Center',
                  lat : 34.073572,
                  long : -118.399767
              },
              {
                  place : 'Staples Center',
                  desc : 'City of Joy...',
                  lat : 34.043284,
                  long : -118.267254
              },
          ];
var roadroute=[];
  
  

          //Angular App Module and Controller
          var mapApp = angular.module('mapApp', []);
          mapApp.controller('MapController', function ($scope) {
              
              var mapOptions = {
                  zoom: 10,
                  center: new google.maps.LatLng(34.090655,-118.339585),
                  mapTypeId: google.maps.MapTypeId.ROADMAP
              }

              $scope.map = new google.maps.Map(document.getElementById('map'), mapOptions);

              $scope.markers = [];
              
              var infoWindow = new google.maps.InfoWindow();
              
              var createMarker = function (info){
                  
                  var marker = new google.maps.Marker({
                      map: $scope.map,
                      position: new google.maps.LatLng(info.lat, info.long),
                      title: info.place
                  });
                  marker.content = '<div class="infoWindowContent">' + info.desc + '<br />' + info.lat + ' E,' + info.long +  ' N, </div>';
                  
                  google.maps.event.addListener(marker, 'click', function(){
                      infoWindow.setContent('<h2>' + marker.title + '</h2>' + 
                        marker.content);
                      infoWindow.open($scope.map, marker);
                  });
                  
                  $scope.markers.push(marker);
                  
              }

            $scope.ChileTrip1=[];
            for (k=0;k < cities.length;k++){

            $scope.ChileTrip1[k]=new google.maps.LatLng(cities[k].lat,cities[k].long);



            }
            
            for (i = 0; i < cities.length; i++){
                createMarker(cities[i]);
            }
        
            
        $scope.traceChileTrip1=new google.maps.Polyline({
        path:$scope.ChileTrip1,
        strokeColor:"blue",
        strokeOpacity:1.0,
        strokeWeight:2
          
        });
        $scope.service1 = new google.maps.DirectionsService(),$scope.traceChileTrip1, snap_path1 = [];
                   
            
        $scope.traceChileTrip1.setMap(map);


         for (j = 0; j < $scope.ChileTrip1.length - 1; j++) {
                           $scope.service1.route({
                                origin: $scope.ChileTrip1[j],
                                destination: $scope.ChileTrip1[j + 1],
                                travelMode: google.maps./*Directions*/TravelMode.DRIVING
                                }, function (result, status) {
                                      if (status == google.maps.DirectionsStatus.OK) {
                                          snap_path1 = snap_path1.concat(result.routes[0].overview_path);
                                          $scope.traceChileTrip1.setPath(snap_path1);
                                      } else console.log("Directions request failed: " + status);
                           });
                         }
                    
            
                    
                $scope.openInfoWindow = function(e, selectedMarker){
                    e.preventDefault();
                    google.maps.event.trigger(selectedMarker, 'click');
                }

            });
<!DOCTYPE html>
<html ng-app="mapApp">
<head>
<meta charset="ISO-8859-1">
<title>Maps in AngularJS</title>
<link rel="stylesheet" href="map.css">

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=en"></script>
<script type="text/javascript" src="map.js"></script>
</head>
<body>
<div class="container">
  <h2>Dynamic Tabs</h2>
  <ul class="nav nav-tabs">
    <li class="active"><a href="#home">Home</a></li>
    <li><a href="#menu1">Menu 1</a></li>
    <li><a href="#menu2">Menu 2</a></li>
    <li><a href="#menu3">Menu 3</a></li>
  </ul>

  <div class="tab-content">
    <div id="home" class="tab-pane fade in active">
      <div ng-controller="MapController">
         <div id="map"></div>
         <div id="repeat" ng-repeat="marker in markers | orderBy : 'title'">
            <a id="country_container" href="#" ng-click="openInfoWindow($event, marker)">
            <label id="names" >{{marker.title}}</label></a>
         </div>
 
       </div>
    </div>
    <div id="menu1" class="tab-pane fade">
      <h3>Menu 1</h3>
      <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
    </div>
    <div id="menu2" class="tab-pane fade">
      <h3>Menu 2</h3>
      <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
    </div>
    <div id="menu3" class="tab-pane fade">
      <h3>Menu 3</h3>
      <p>Eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
    </div>
  </div>
</div>

<script>
$(document).ready(function(){
    $(".nav-tabs a").click(function(){
        $(this).tab('show');
    });
});
</script>



</body>
</html>

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

Utilizing jQuery to implement a CSS style with a fading effect, such as FadeIn()

I have a jQuery script that applies a CSS style to an HTML table row when the user clicks on a row link: $(this).closest('tr').css("background-color", "silver"); Is there a way to soften this color change effect, such as by gradually fading in ...

Implement a JavaScript function that loads fresh content onto the webpage without the need to refresh the

$("span.removeFromCart").on("click",function(){ var id = $(this).attr("data-id"); $.ajax({ type: "GET", url: "ajax.php?id="+id+"&action=remove" }) .don ...

How to delete a specific element from the DOM using its ID in JavaScript

I am facing a challenge in removing an element from the page dynamically without refreshing using JavaScript. The script I have written successfully deletes the record from the database, but I need assistance in removing the container element based on it ...

How to dynamically update data in Angular without the need for a page refresh or loading?

Looking to enhance a wishlist feature by enabling users to delete items from the list without the need for a page refresh. Here's my approach: wish.controller('wishCtrl',['$scope','$http','$cookies','$wind ...

What is the best way to add JSON data to a table?

I have developed a php script to create json data. However, I am facing an issue while trying to display this generated json data in a table. While my php code successfully generates the data, it is unable to insert it into the table. I would appreciate an ...

Confirmation dialog for deletion may not function properly upon initial click

When the delete button is clicked, I would like to display a confirmation dialog using an easy-to-use plugin. The button's HTML code is as follows: <button type="button" class="btn contactDeleteRow" /> Here is my JavaScript code: $(document). ...

Is there a way for me to showcase all questions along with their respective choices in my view simultaneously?

Here is an array of responses: [ { "id":16, "question":"Who is this message for?", "duration":60, "choices":[ { "id":61, "question_ ...

Top Tip for conditionally rendering a styled component inside or outside a wrapper, depending on the screen width

Can anyone help me with this coding question? I'm currently trying to determine the most efficient way to conditionally place the code inside or outside of the wrapper. However, I am unsure what the best practice for this would be. This process seems ...

Utilizing jQuery time intervals within a jQuery click event: A step-by-step guide

For my dropdown menu project, I am facing an issue where the menu bar is not reappearing after collapsing the dropdown. It seems that the jQuery function responsible for toggling classes within a time interval is not executing properly. Specifically, the " ...

Error: Reactjs - Attempting to access the 'name' property of an undefined variable

As I continue to learn about React, I have been experimenting with props in my code. However, I encountered an error where the prop is appearing as undefined. This issue has left me puzzled since I am still at a basic level of understanding React. If anyo ...

What is the purpose of being able to include additional scripts within package.json files?

I am attempting to include a new script in the package.json file under the scripts section. For instance, I have the following: { "scripts": { "delete": "rm -f wwwroot/*.js wwwroot/*.css wwwroot/*.html wwwroot/*.map" "watch": "npm run delete; parc ...

JS URL verification: ensuring valid URLs with JavaScript

Is it possible to combine two scripts that perform separate actions, one clicking a button and opening a new window, and the other interacting with elements in that new window simultaneously? function run() { var confirmBtn = document.querySelector(".sele ...

The requested :id route could not be found using the findById() method in

Having trouble retrieving data using Insomnia from a specific ID in my collection. Below is the sample request URL. http://localhost:5000/todos/5dd295a49d5d7a0b7a399bbe However, when I access http://localhost:5000/todos/ without the ID, I can see all the ...

Preventing Duplicate Random Numbers in Vue 3 and JavaScript: A Guide

I've been working on creating a function that can iterate through an array of objects with names and IDs, randomize the array, and then return one filtered item to slots.value. The current spin function successfully loops through the randomized object ...

Troubleshooting Spring's difficulty in locating resource files (css, jsp...)

Currently, I am integrating a jsp file as a model from a Controller and aiming to incorporate CSS styles and JS libraries into the project structure. Project Structure Webcontent assets WEB-INF jsp For the configuration in web.xml: <web-app versio ...

Tips for retaining JWT token in local storage even after a page refresh

I am currently working on implementing a login/logout feature and utilizing the context API to manage functions such as storing tokens in local storage and removing them upon logging out. However, I have encountered an issue where the token stored in local ...

Issues with the functionality of minimized AngularJS JavaScript files

I combined all JS files into one and minified them, but now none of the site features are working. There were too many separate JS files to include individually, so I decided to merge them together. Is there a better method to reduce the number of HTTP r ...

Ways to extract information from a JSON dataset

[{"id":7,"message":"This is just a sample message","taker_id":"131","giver_id":"102","status":"0","stamp":"2016-08-11"}] Here is my answer. I am attempting to retrieve some data. I have attempted using data.id but it is unsuccessful and gives me undefined ...

Submitting an ajax form with the use of the symbol '&'

I am currently working on a form submission using the .ajax() method. Within my script, I have the following code: data: dataString, The variable dataString is composed of: var list = $('.listsummary').val() The listsummary class is assoc ...

Unable to locate additional elements following javascript append utilizing Chrome WebDriver

I have a simple HTML code generated from a C# dotnet core ASP application. I am working on a webdriver test to count the number of input boxes inside the colorList div. Initially, the count is two which is correct, but when I click the button labeled "+", ...