0

i use gmap3 plugin for show result in google map have text box field , when someone type for example "new york" many marker in the new york town , i want map zoom and fit in new york and show all of the marker in this place? how to can do it? for show to your what i want look at this site : padmapper.com

and this is my code :

$(function(){
           $("#main-map").gmap3({
      map:{
        options:{
          center:["newyork"]
        }
      },
      marker:{
        values:[
          {latLng:[48.8620722, 2.352047]},
          {address:"86000 Poitiers, France"},
          {address:"66000 Perpignan, France"}
        ],
      }
    });
    $('#ok').click(function(){
      var addr = $('#Address').val();
      if ( !addr || !addr.length ) return;
      $("#main-map").gmap3({
        getlatlng:{
          address:  addr,
          callback: function(results){
            if ( !results ) return;
            $(this).gmap3({
              marker:{                              
                latLng:results[0].geometry.location,
                map:{
                    options:{
                    center: addr ,
                    zoom: 12
                    },
                  center: addr
                }
              }
            });
          }
        }
      });
    });

    $('#Address').keypress(function(e){
      if (e.keyCode == 13){
        $('#ok').click();
      }
    });
  });

and html code

    <div id="main-map">
        </div>
    <input type="text" placeholder="City, Address, or Zip" name="goToAddress" style="margin-left:5px; width:215px;" id="Address">
<button id="ok" type="button">Go</button>
shahriyar3
  • 79
  • 10

1 Answers1

3

try this

$('#ok').click(function(){
  var addr = $('#Address').val();
  if ( !addr || !addr.length ) return;
  $("#main-map").gmap3({
    getlatlng:{
      address:  addr,
      callback: function(results){
        if ( !results ) return;
        $(this).gmap3({
          marker:{                              
            latLng:results[0].geometry.location,

          }
          {action: 'setCenter', args:[ result[0].geometry.location ]}
        });
      }
    }
  });
});
N B
  • 391
  • 3
  • 12