Google Map Address

Google Map address

by Avinashullal

HTML

<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;extension=.js"></script>
<div style="width: 100%"><iframe width="100%" height="400" src="https://maps.google.com/maps?width=100%&amp;height=400&amp;hl=en&amp;coord=26.217132083524525, 50.19717693328858&amp;q=Al-Khobar%20Kingdom%20of%20Saudi%20Arabia%20BASETECH+(Basetec)&amp;ie=UTF8&amp;t=&amp;z=16&amp;iwloc=B&amp;output=embed" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"><a href="https://www.maps.ie/create-google-map/">Google map generator</a></iframe></div><br />

CSS

#map-canvas {
      height: 300px;
      width: 100%
  }
  #geo-error {
      height: 50px;
      width: 100%;
      color:red;
      background-color:yellow;
      margin-bottom:10px;
  }

JavaScript

debugger;
var latlng;

function initializeMap() {
    var address = document.getElementById("address").value;
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({
        'address': address
    }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            latlng = results[0].geometry.location;
            var mapOptions = {
                zoom: 16,
                center: latlng
            }
            map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
            var marker = new google.maps.Marker({
                map: map,
                draggable: true,
                position: latlng
            });
            google.maps.event.addListener(marker, 'dragend', function () {
                latlng = marker.getPosition();
            });
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });
}

function saveMap() {
    alert("your lat is " + latlng);
}