Google maps search box outside map

前端 未结 2 1424
面向向阳花
面向向阳花 2021-01-31 22:09

I\'m playing with the Google Maps API, and I\'ve inserted a search-form with autocomplete. The problem is that the input-box is stuck into the map. I can\'t display it outside t

相关标签:
2条回答
  • 2021-01-31 22:28

    Basically if I understand it well, you want to have an input with autocomplete that update the Google maps. But you want it outside the map

    This line, is what bind your input to the map. You don't need it

    map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
    

    Then you just remove the left: 1000px from your input and that's it.

    http://jsfiddle.net/KyMCy/5/

    0 讨论(0)
  • 2021-01-31 22:32

    All you need here is to load the Places library. You don't even need to display a map.

    new google.maps.places.Autocomplete(
      (document.getElementById('autocomplete')), {
        types: ['geocode']
      });
    #autocomplete {
      width: 300px;
    }
    <input id="autocomplete" placeholder="Enter your address" type="text"></input>
    
    <script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>

    0 讨论(0)
提交回复
热议问题