title: Adding marker on Google Maps using a button
body: <p>I'm trying to add a marker using a button in Google Maps and I'm getting the error, cannot read property lat of null. I'm not that good in Javascript, any help?</p>
  
  <pre><code> function setmarker(){
          setLatLng = new google.maps.LatLng(document.getElementById('latitude').value,document.getElementById('longitude').value); 
          alert(setLatLng);
          var map = new google.maps.Map(document.getElementById('map-canvas'),
            mapOptions);
  
          var mapOptions = {
          zoom: 8,
          //center: new google.maps.LatLng(-1.2921897,36.8288574)
        };
  
  
          var marker = new google.maps.Marker({
            position: setLatLng,
            map: map,
            title: 'Obtained coordinate'
          });
  
      }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
  &lt;div id="map-canvas"&gt;&lt;/div&gt;
  
  
  &lt;div class="side-panel"&gt;
    &lt;div&gt;Latitude:&lt;br&gt;&lt;input type="text" name="latitude" id="latitude" &gt;&lt;/div&gt;
    &lt;div&gt;Longitude:&lt;br&gt;&lt;input type="text" name="longitude" id="longitude"&gt;&lt;/div&gt;&lt;br&gt;
    &lt;!-- &lt;input type="submit" onsubmit="setmarker();"&gt; --&gt;
    &lt;button onclick="setmarker()"&gt;Show Marker&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>