Q:

How to draw a line and a box on gmaps?

I've seen this tool which let you draw a line on gmaps and it generates the js code for you
So the JS is:
var myCoordinates = [
  new google.maps.LatLng(48.955410,10.034749),
  new google.maps.LatLng(59.648652,29.898030)
];
var polyOptions = {
  path: myCoordinates,
  strokeColor: "#FF0000",
  strokeOpacity: 1,
  strokeWeight: 3
}
var it = new google.maps.Polyline(polyOptions);
it.setMap(map);

What I would like to do is to start the line from a pin I receive and not a pin I set when I click as per that tool and then I would to draw a infobox at the end of that line (so not where it starts form the pin).
What I am aiming for is to draw a line form a starting point and have an infobox such as per this image below, see the lines on the map

Therefore I can pass the coords here:
  new google.maps.LatLng(48.955410,10.034749),
  new google.maps.LatLng(59.648652,29.898030)

But how would I target the end of the line and place text there?
With this answer I can define a start and end, but how to draw a box at the end point?

A:

I think you can do it using a marker at the end point of the line, then attaching, for example an infoWindow, at the end and finally hiding the marker.
function initMap() {

  var coordinates = {
    lat: 40.785845,
    lng: -74.020496
  };

  var coordinates2 = {
    lat: 40.805845,
    lng: -74.130496
  };

  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 10,
    center: coordinates,
    scrollwheel: false
  });

  var marker = new google.maps.Marker({
    position: coordinates,
    map: map
  });

    var infoMarker = new google.maps.Marker({
    position: coordinates2,
    map: map
  });

  var infowWindow = new google.maps.InfoWindow();

    var line = new google.maps.Polyline({
    path: [
      marker.position,
      infoMarker.position
    ],
    strokeColor: "#FF0000",
    strokeOpacity: 1,
    strokeWeight: 3
  });

  line.setMap(map);

  infowWindow.setContent("<b>Hello world!</b>");
  infowWindow.open(map, infoMarker);
  infoMarker.setVisible(false);
}

google.maps.event.addDomListener(window, "load", initMap);

Check it working on this jsfiddle

