Google maps api 3 获取Google Map Api v3的Select2值

Google maps api 3 获取Google Map Api v3的Select2值,google-maps-api-3,jquery-select2,Google Maps Api 3,Jquery Select2,我最近将我的选择菜单从标准格式更改为选择2菜单。由于此“更改我的值”字段似乎没有将值带到地图上。当我从列表中选择一个项目时,它会触发地图上相应的信息框来显示,但他的信息框已经停止工作。有什么想法吗 谷歌地图代码示例: <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng(42.3443961,-71.0853170);

我最近将我的选择菜单从标准格式更改为选择2菜单。由于此“更改我的值”字段似乎没有将值带到地图上。当我从列表中选择一个项目时,它会触发地图上相应的信息框来显示,但他的信息框已经停止工作。有什么想法吗

谷歌地图代码示例:

<script type="text/javascript">
    function initialize() {
        var latlng = new google.maps.LatLng(42.3443961,-71.0853170);
        var settings = {
            zoom: 14,
            center: latlng,
            mapTypeControl: true,
            mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
            navigationControl: true,
            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
            mapTypeId: google.maps.MapTypeId.ROADMAP};
        var map = new google.maps.Map(document.getElementById("map_canvas"), settings);

<!--START Boston Medical Center-->      
        var contentStringboscen = '<div class="contentmap">'+
            '<div id="siteNotice">'+
            '</div>'+
            '<h2 id="firstHeading" class="firstHeading">Boston Medical Center</h2>'+
            '<div id="bodyContent">'+
            '<p>Boston Medical Center (BMC) is a 496-bed academic medical center located in Boston’s historic South End. The hospital is the primary teaching affiliate for Boston University School of Medicine.</p>'+
            '</div>'+
            '</div>';
        var infowindow = new google.maps.InfoWindow({
            content: contentStringboscen
        });

        var boscenImage = new google.maps.MarkerImage('images/map-icons/local-attractions/a.png',
            new google.maps.Size(40,50),
            new google.maps.Point(0,0),
            new google.maps.Point(50,50)
        );

        var boscenShadow = new google.maps.MarkerImage('images/map-icons/local-attractions/a-shadow.png',
            new google.maps.Size(40,50),
            new google.maps.Point(0,0),
            new google.maps.Point(65, 50));

        var boscenPos = new google.maps.LatLng(42.3344236,-71.0744651);

        var boscenMarker = new google.maps.Marker({
            position: boscenPos,
            map: map,
            icon: boscenImage,
            shadow: boscenShadow,
            title:"Boston Medical Center",
            zIndex: 3});
<!--STOP Boston Medical Center-->

<!--START Boston Public Library-->      
        var contentStringboslib = '<div class="contentmap">'+
            '<div id="siteNotice">'+
            '</div>'+
            '<h2 id="firstHeading" class="firstHeading">Boston Public Library</h2>'+
            '<div id="bodyContent">'+
            '<p>The Boston Public Library (est.1848) is a municipal public library system in Boston, Massachusetts, United States. It was the first publicly supported municipal library in the United States, the first large library open to the public in the United States, and the first public library to allow people to borrow books and other materials and take them home to read and use.</p>'+
            '</div>'+
            '</div>';
        var infowindow = new google.maps.InfoWindow({
            content: contentStringboslib
        });

        var boslibImage = new google.maps.MarkerImage('images/map-icons/local-attractions/b.png',
            new google.maps.Size(40,50),
            new google.maps.Point(0,0),
            new google.maps.Point(50,50)
        );

        var boslibShadow = new google.maps.MarkerImage('images/map-icons/local-attractions/b-shadow.png',
            new google.maps.Size(40,50),
            new google.maps.Point(0,0),
            new google.maps.Point(65, 50));

        var boslibPos = new google.maps.LatLng(42.349484,-71.077740);

        var boslibMarker = new google.maps.Marker({
            position: boslibPos,
            map: map,
            icon: boslibImage,
            shadow: boslibShadow,
            title:"Boston Public Library",
            zIndex: 3});
<!--STOP Boston Public Library-->

        google.maps.event.addListener(boscenMarker, 'click', function() {
            infowindow.setContent(contentStringboscen);
            infowindow.open(map,boscenMarker);
        });
        google.maps.event.addListener(boslibMarker, 'click', function() {
            infowindow.setContent(contentStringboslib);
            infowindow.open(map,boslibMarker);
        });

        var selectChoices = {
            boscenChoice: boscenMarker,
            boslibChoice: boslibMarker,
        };

        google.maps.event.addDomListener(
            document.getElementById("selectLocation"), 'change',
            function() {
            google.maps.event.trigger(selectChoices[this.value], "click");
        });

    }
</script>

函数初始化(){
var latlng=新的google.maps.latlng(42.3443961,-71.0853170);
变量设置={
缩放:14,
中心:拉特林,
mapTypeControl:true,
mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU},
导航控制:对,
navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL},
mapTypeId:google.maps.mapTypeId.ROADMAP};
var map=new google.maps.map(document.getElementById(“map_canvas”),设置);
var contentStringboscen=“”+
''+
''+
“波士顿医疗中心”+
''+
“波士顿医学中心(BMC)是一个拥有496张床位的学术医疗中心,位于波士顿历史悠久的南端。该医院是波士顿大学医学院的主要教学附属机构。

”+ ''+ ''; var infowindow=new google.maps.infowindow({ 内容:ContentStringBossen }); var boscenImage=new google.maps.MarkerImage('图像/地图图标/当地景点/a.png', 新谷歌地图尺寸(40,50), 新google.maps.Point(0,0), 新谷歌地图点(50,50) ); var bossenshadow=new google.maps.MarkerImage('图像/地图图标/当地景点/a-shadow.png', 新谷歌地图尺寸(40,50), 新google.maps.Point(0,0), 新的google.maps.Point(65,50)); var boscenPos=new google.maps.LatLng(42.3344236,-71.0744651); var boscenMarker=新的google.maps.Marker({ 职位:boscenPos, 地图:地图, 图标:boscenImage, 影子:博森沙多, 标题:“波士顿医疗中心”, zIndex:3}); var contentStringboslib=“”+ ''+ ''+ “波士顿公共图书馆”+ ''+ 波士顿公共图书馆(美国东部1848年)是美国马萨诸塞州波士顿市的一个市政公共图书馆系统。它是美国第一个公共支持的市政图书馆,是美国第一个向公众开放的大型图书馆,也是第一个允许人们借阅书籍和其他资料并带回家阅读和使用的公共图书馆。

'+ ''+ ''; var infowindow=new google.maps.infowindow({ 内容:contentStringboslib }); var boslibImage=new google.maps.MarkerImage('图像/地图图标/本地景点/b.png', 新谷歌地图尺寸(40,50), 新google.maps.Point(0,0), 新谷歌地图点(50,50) ); var boslibShadow=new google.maps.MarkerImage('图像/地图图标/本地景点/b-shadow.png', 新谷歌地图尺寸(40,50), 新google.maps.Point(0,0), 新的google.maps.Point(65,50)); var boslibPos=new google.maps.LatLng(42.349484,-71.077740); var boslibMarker=new google.maps.Marker({ 职位:boslibPos, 地图:地图, 图标:boslibImage, 影子:博斯利影子, 标题:“波士顿公共图书馆”, zIndex:3}); google.maps.event.addListener(Bossenmarker,'click',function(){ infowindow.setContent(contentStringBossen); 信息窗口。打开(地图、Bossenmarker); }); google.maps.event.addListener(boslibMarker,'click',function(){ setContent(contentStringboslib); 打开(地图、标记); }); var selectChoices={ 博森选择:博森马克, boslibChoice:boslibMarker, }; google.maps.event.addDomListener( document.getElementById(“selectLocation”),“change”, 函数(){ google.maps.event.trigger(选择Choices[this.value],“单击”); }); }
选择2代码:

<link type="text/css" rel="stylesheet" href="select2/select2.css">
<script src="select2/select2.js"></script>
<script>
var men=jQuery;
    men.noConflict();
men(document).ready(function() {
men('#selectLocation').select2(
    {
        placeholder: "Choose an Attraction",
        width:'400px',
        formatResult: format,
        formatSelection: format,
    });
function format(option) {
    if (option.id.indexOf('Choice') != -1) {
        return "<span style='display:inline-block;width:20px'>" + option.text.substring(0,2) + "</span>" + option.text.substring(2)
    } else {
        return option.text
    }
}
});
</script>

var-men=jQuery;
男人。没有冲突();
人员(文件).准备就绪(功能(){
男子(“#选择地点”)。选择2(
{
占位符:“选择一个景点”,
宽度:'400px',
formatResult:format,
格式选择:格式,
});
函数格式(选项){
if(option.id.indexOf('Choice')!=-1){
返回“+option.text.substring(0,2)+”+option.text.substring(2)
}否则{
返回option.text
}
}
});
选择2菜单:

<div class="general-bg" style="background-color:#ffffff; border-bottom:solid 1px #cccccc">
    <div id="map-nav" style="width:400px;margin:10px auto 10px auto; background-color:#ffffff;">
        <select id="selectLocation" style="color:#09F; font-size:18px; font-family:'Century Gothic W01';" name="categories">
            <option></option>
            <option value='boscenChoice'>A. Boston Medical Center</option>
            <option value='boslibChoice'>B. Boston Public Library</option>
            <option value='chrcenChoice'>C. Christian Science Center</option>
            <option value='chuapaChoice'>D. Church Park Apartments</option>
            <option value='copplaChoice'>E. Copley Place Shopping</option>
            <option value='fenparChoice'>F. Fenway Park</option>
            <option value='findisChoice'>G. Financial District</option>
            <option value='houbluChoice'>H. House of Blues</option>
            <option value='huntheChoice'>I. Huntington Theatre</option>
            <option value='isamusChoice'>J. Isabella Stewart Gardener Museum</option>
            <option value='logairChoice'>K. Logan International Airport</option>
            <option value='lonmedChoice'>L. Longwood Medical and Academic Area</option>
            <option value='mashosChoice'>M. Massachusetts General Hospital</option>
            <option value='mastecChoice'>N. Massachusetts Institute of Technology</option>
            <option value='musartChoice'>O. Museum of Fine Arts</option>
            <option value='newstrChoice'>P. Newbury Street Shopping</option>
            <option value='prucenChoice'>Q. Prudential Center Shopping</option>
            <option value='pubgarChoice'>R. Public Garden</option>
            <option value='symhalChoice'>S. Symphony Hall</option>
        </select>
    </div>
</div>

A.波士顿医疗中心
波士顿公共图书馆
C.基督教科学中心
教堂公园公寓
科普利购物中心
芬威公园
G.金融区
H.布鲁斯之家
一、亨廷顿剧院
伊莎贝拉·斯图尔特园丁博物馆
K.洛根国际机场
L.朗伍德医学和学术领域
M.马萨诸塞州总医院
美国麻省理工学院
O.美术馆
纽伯里街购物中心
Q.保诚购物中心
R.公共花园
美国交响乐厅

您的问题来自Select2行为

当您在Select2中选择一个新条目时,
中的
上的html属性将不会像正常选择一样更新为“已选择”。选择2将在exchange中更新
并触发javascript中的2事件:
更改