Angularjs google maps API drawing polyline -
following code snippet gives me output (basically on each click new marker added , fetching it's lat , long values):
0: latitude: 40.207196906764054 longitude: -99.68994140625 1: latitude: 40.202477129519124 longitude: -99.60823059082031
code snippet:
$scope.map.markers.push(marker); // console.log($scope.map.markers); (var item in $scope.map.markers) { console.log(item +': '+ "latitude: " + $scope.map.markers[item].coords.latitude + " " + "longitude: " + $scope.map.markers[item].coords.longitude); }
to draw polyline need array in such format:
var flightplancoordinates = [ {lat: 37.772, lng: -122.214}, {lat: 21.291, lng: -157.821}, {lat: -18.142, lng: 178.431}, {lat: -27.467, lng: 153.027} ];
i want draw lines along these markers. how can construct such structure inside loop add these lat , long values can feed 'path' variable polilines?
you should able loop trough markers , add coordinates empty array (provided cycle shown works):
var mycoordinates = []; (var item in $scope.map.markers) { mycoordinates.push({lat: $scope.map.markers[item].coords.latitude, lng: $scope.map.markers[item].coords.longitude}); }
and use mycoordinates
array same way use flightplancoordinates
create polyline, e.g.:
var mypolyline = new google.maps.polyline({ path: mycoordinates, geodesic: true, strokecolor: '#ff0000', strokeopacity: 1.0, strokeweight: 2, map: map });
Comments
Post a Comment