I am attempting to create a simple polyline connecting two markers using Angular-google-maps. While I have successfully positioned my two markers, I am encountering some complexity when trying to draw a polyline between them.
It seems that my logic may not be correct. Initially, I tried storing the position of each marker in a variable and then placing it in an array. However, when attempting to convert this into a google.maps.LatLng() object, the object appears to be empty, as shown in my console:
_.L lat:ƒ() lng:ƒ() __proto__: Object
Below is the function I am using:
function drawline (position){
if (position.latitude === '' || position.longitude === '' ) return;
var emitterName = position.username;
if (emitterName == "emitter-python") {
var coor = [position.latitude, position.longitude];
var lineCoordinates = new google.maps.LatLng({latitude: coor[0],longitude: coor[1]});
console.log("coor:", coor); //Print [5,5]
}else {
console.log("not emitter1");
}
if (emitterName == "emitter-python2") {
var coor1 = [position.latitude, position.longitude];
var lineCoordinates1 = new google.maps.LatLng({latitude: coor1[0],longitude: coor1[1]});
console.log("coor1:", coor1); //Print [5,6]
}else{
console.log("not emitter2");
}
var pathLine = [
lineCoordinates,
lineCoordinates1
];
$scope.polylines = [{
path: pathLine,
stroke: {
color: '#000000',
weight: 3
},
editable: false,
draggable: false,
geodesic: true,
visible: true,
}];
}