How to dynamically get the marker location in google map?


<script src=""></script>

<script src="" type="text/javascript">

<input type="text" id="searchmap" name ="Location" placeholder="Enter the Location"><br>
<div id="map-canvas"></div>

<input type="text" class="form-control input-sm" name="lat" id="lat">

<input type="text" class="form-control input-sm" name="lng" id="lng">

  var map = new google.maps.Map(document.getElementById('map-canvas'), {
      lat: 12.971599,
      lng: 77.594563
  var marker = new google.maps.Marker({
    position: {
      lat: 12.971599,
      lng: 77.594563
    map: map,
    draggable: true

  var searchBox = new google.maps.places.SearchBox(document.getElementById('searchmap'));
    var places = searchBox.getPlaces();
    var bounds = new google.maps.LatLngBounds();
    var i,place;
    for(i=0; place=places[i]; i++){

    var lat = marker.getPosition().lat();
    var lng = marker.getPosition().lng();


Hi @gitnaveena,

Thanks for your Google Maps JavaScript API code.

Would you be willing to also supply us with some HTML and CSS to accompany the script, in order to make it easier for users to try it out? You don't need to supply an API key with it. Instead, users could copy your code, and then either open it on their local machine or add their own API key to it.


@appylpye Thanks for the suggestion , I have posted my code with HTML


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.