title: Bring in Google maps 'infowindow' information for current location
body: <p>I am using the Google Maps Javascript API.  The sample code; I think gets me close but doesn't accomplish what I hoped for.</p>
  
  <p>I hard code a 'placeid'
  I am hoping to bring in my current location instead.
  I do bring in my current location in the sample code but the Infowindow information is hard coded.</p>
  
  <p>I am hoping to learn how to bring in both the 'Current Location' marker and 'Infowindow' place information dynamically without the need to hard code it.   </p>
  
  <p>My broken script follows>></p>
  
  <pre><code>&lt;script&gt;
      function initMap() {
          var map = new google.maps.Map(document.getElementById('map'), {
              center: {
                  lat: 42.0491125,
                  lng: -92.91123340000001
              },
              zoom: 12
          });
  
          var infowindow = new google.maps.InfoWindow();
          //       var infoWindow = new google.maps.InfoWindow({map: map});
          var service = new google.maps.places.PlacesService(map);
          service.getDetails({
              // I would like to bring in the current position not a static place id
              placeId: 'EioxMDEgRSBNYWluIFN0LCBNYXJzaGFsbHRvd24sIElBIDUwMTU4LCBVU0E'
          }, function(place, status) {
              if (status === google.maps.places.PlacesServiceStatus.OK) {
                  var marker = new google.maps.Marker({
                      map: map,
                      position: place.geometry.location
                  });
                  google.maps.event.addListener(marker, 'click', function() {
                      infowindow.setContent('&lt;div&gt;&lt;strong&gt;' + place.name + '&lt;/strong&gt;&lt;br&gt;' +
                          'lat lng: ' + place.geometry.location + '&lt;br&gt;' +
                          place.formatted_address + '&lt;/div&gt;');
                      infowindow.open(map, this);
                  });
              }
          });
  
          var infoWindow = new google.maps.InfoWindow({
              map: map
          });
  
          // Try HTML5 geolocation.
          if (navigator.geolocation) {
              navigator.geolocation.getCurrentPosition(function(position) {
                  var pos = {
                      lat: position.coords.latitude,
                      lng: position.coords.longitude
                  };
  
                  infoWindow.setPosition(pos);
                  infoWindow.setContent('Home Point.');
                  map.setCenter(pos);
  
                  var marker = new google.maps.Marker({
  
                      title: 'Your current location',
                      map: map,
                      //  title: 'Your current location'
                  });
  
              }, function() {
                  handleLocationError(true, infoWindow, map.getCenter());
              });
          } else {
              // Browser doesn't support Geolocation
              handleLocationError(false, infoWindow, map.getCenter());
          }
      }
  
      function handleLocationError(browserHasGeolocation, infoWindow, pos) {
          infoWindow.setPosition(pos);
          infoWindow.setContent(browserHasGeolocation ?
              'Error: The Geolocation service failed.' :
              'Error: Your browser doesn\'t support geolocation.');
      }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div id="map"&gt;&lt;/div&gt;
      &lt;script async defer src="https://maps.googleapis.com/maps/api/js? key=YOUR_API_KEY&amp;libraries=places&amp;callback=initMap"&gt;
      &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>