Javascript 从HTML选择选项查询谷歌地图支持的地点的问题

Javascript 从HTML选择选项查询谷歌地图支持的地点的问题,javascript,jquery,google-maps-api-3,Javascript,Jquery,Google Maps Api 3,我试图从HTML选择选项列表中查询谷歌地图上支持的位置。这是我正在使用的列表 <select class="selectpicker" class="span2" id="gPlaces"> <optgroup label="Picnic"> <option value="accounting">Accounting</option> <option value="airport">Airport</option&g

我试图从HTML选择选项列表中查询谷歌地图上支持的位置。这是我正在使用的列表

<select class="selectpicker" class="span2" id="gPlaces">
 <optgroup label="Picnic">
   <option value="accounting">Accounting</option>
   <option value="airport">Airport</option>
   <option value="amusement_park">Amusement Park</option>
 </optgroup>
</select>
并使用findPlaces()中的“strPlace”将我的查询设置为:

var request = {
                bounds: boxes[searchIndex],
                types: [strPlace]
               };
但不管出于什么原因,它都不起作用。我还绑定了使用jquery.ready()获取选择值的函数,如下所示:

但我得到的是:

你能告诉我我做错了什么吗?谢谢

更新:

<script type="text/javascript">
        var map = null;
        var boxpolys = null;
        var directions = null;
        var routeBoxer = null;
        var distance = null; // km
        var service = null;
        var gmarkers = [];
        var infowindow = new google.maps.InfoWindow();
        var e = document.getElementById("gPlaces");
        var strPlace = e.options[e.selectedIndex].value;

var-map=null;
var-boxpolys=null;
var方向=null;
var routeBoxer=null;
变量距离=null;//公里
var服务=null;
var gmarkers=[];
var infowindow=new google.maps.infowindow();
var e=document.getElementById(“gPlaces”);
var strPlace=e.options[e.selectedIndex].value;
试试:

  • $(function(){…})
    结构中的所有内容进行措辞
  • 将“更改”事件处理程序附加到“选择”菜单,以便在用户进行选择时执行Google Maps Supported Places查询
Javascript:

$(function() {
    ...
    $("#gPlaces").on('change', function() {
        var strPlace = $(this).val();
        alert( strPlace );
        // Use `strPlace` and other vars here to build and execute
        // your Google Maps Supported Places query.
    });
    ...
});

您在何处/何时执行定义
e
strPlace
的行?感谢您的回复,实际上我没有执行它们?我只是在脚本顶部声明了它们。请查看postWait的更新部分,您正在设置脚本顶部的
strPlace
“的值”?不是在你真正需要价值的时候?在您实际需要该值之前,不应运行该代码,否则您将无法获得用户当前选择的内容。(您希望脚本顶部的
e.selectedIndex
的值是多少?)从描述中可以看出,这应该在
findPlaces()函数中设置。你能发布一个完整的例子吗?这使用了一个地方类型的下拉列表。再次感谢geocodeZip,就像你总是有答案一样!
<script type="text/javascript">
        var map = null;
        var boxpolys = null;
        var directions = null;
        var routeBoxer = null;
        var distance = null; // km
        var service = null;
        var gmarkers = [];
        var infowindow = new google.maps.InfoWindow();
        var e = document.getElementById("gPlaces");
        var strPlace = e.options[e.selectedIndex].value;
$(function() {
    ...
    $("#gPlaces").on('change', function() {
        var strPlace = $(this).val();
        alert( strPlace );
        // Use `strPlace` and other vars here to build and execute
        // your Google Maps Supported Places query.
    });
    ...
});