sensei
sensei

Reputation: 7562

Angular ngMap Google Directions waypoint doesn't recognize array

I am trying to use waypoints in array:

var way = [{ location: { lat: 51.546550, lng: 0.026345 }, stopover: true }, { location: { lat: 51.5493953, lng: 0.0412878 }, stopover: true }];

And load on map like this:

        <ng-map center="51.546550, 0.026345" zoom="13">
            <directions draggable="true"
                        panel="directions-panel"
                        waypoints="way"
                        origin="51.546550, 0.026345"
                        destination="51.5493953, 0.0412878">
            </directions>               
        </ng-map>

For some reason the error I am getting is:

InvalidValueError: in property waypoints: not an Array

If I use array directly it works:

<ng-map center="51.546550, 0.026345" zoom="13">
            <directions draggable="true"
                        panel="directions-panel"
                        waypoints="[{ location: { lat: 51.546550, lng: 0.026345 }, stopover: true }, { location: { lat: 51.5493953, lng: 0.0412878 }, stopover: true }]"
                        origin="51.546550, 0.026345"
                        destination="51.5493953, 0.0412878">
            </directions>               
        </ng-map>

What am I missing?

Upvotes: 0

Views: 2964

Answers (1)

Naga Sandeep
Naga Sandeep

Reputation: 1431

Update

You can use either waypoints="{{ways}}" or ng-waypoints = "ways". In the below markup I used ng-waypoints. Example here

<ng-map zoom="13" center="51.546550, 0.026345" >
   <directions draggable="true"
                    panel="directions-panel"
                    ng-waypoints='ways'
                    origin="51.546550, 0.026345"
                    destination="51.5493953, 0.0412878">
        </directions>               
  </ng-map>

The js files I used are

<script src="ng-map.js"></script>
<script src="http://maps.google.com/maps/api/js"></script>

Below doesnt work

Can you try $scope.way instead of var way

Upvotes: 2

Related Questions