如何删除Google地图中的pop信息窗口?

时间:2016-06-30 11:29:07

标签: javascript jquery google-maps google-maps-api-3

我的地图中显示一个空信息窗口。我不知道如何删除它。有人帮我解决了这个问题。

this one

<script src="http://code.jquery.com/jquery-1.8.2.min.js"> </script> 
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script> 
<script src="https://maps.googleapis.com/maps/api/js?key=myKey"></script>
<script>
            $(document).on("pageinit", "#map-page", function() {
            i=0;
            setInterval(function(){
            if(i=="0"){
             getcurrentlatlong();}
             i++;
            },2000);               


            });

            function getcurrentlatlong(){
                if (navigator.geolocation)
                {              
                //  //alert("navigator.geolocation is supported");
                  navigator.geolocation.getCurrentPosition(onSuccess, onError, { enableHighAccuracy:true });
                                                //enableHighAccuracy:true means if network not enable then it ask for GPS
                }
                else{
                    //alert("Please Switch ON your GPS ");
                }
            }

            function onSuccess(position) { 
              // enable ur gps, it takes sometime to call till now wait   
               // //alert("onSuccess called");
                var image = 'http://temp.pickzy.com/phonegap/car.png';
                var lat=position.coords.latitude;
                var longi=position.coords.longitude;
               // //alert("latitude is: "+lat+ " longitude is: "+ longi);

                 mapCenter = new google.maps.LatLng(lat, longi),
                 myOptions = {
                     zoom:16,
                     mapTypeId: google.maps.MapTypeId.ROADMAP,
                     center: mapCenter,
                 },
                map = new google.maps.Map(document.getElementById("map_canvas"), myOptions),

                 marker = new google.maps.Marker({
                     position: new google.maps.LatLng(lat, longi),
                     map: map,
                     icon: image,
                     title:"hi",
                     });

                        $('#latiLong').val("("+lat+","+longi+")");

                        var infoWindow = new google.maps.InfoWindow({map: map});
                        var blueCoords = [
                        {lat:1.346414, lng:103.873662},
                        {lat:1.347347, lng:103.873662},
                        {lat:1.347655, lng:103.874402},
                        {lat:1.346828, lng:103.874491},
                        {lat:1.346544,lng:103.874343},
                        {lat:1.346291,lng: 103.874295}
                        ];

                        var redCoords = [
                        {lat: 1.298977,lng: 103.845774},
                        {lat: 1.299176,lng: 103.845690},
                        {lat: 1.299438,lng: 103.845833},
                        {lat: 1.299351,lng: 103.846338},
                        {lat: 1.298831,lng: 103.846031}

        ];

            // Construct a draggable red triangle with geodesic set to true.
          new google.maps.Polygon({
          map: map,
          paths: redCoords,
          strokeColor: '#FF0000',
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: '#FF0000',
          fillOpacity: 0.35,
          draggable: false,
          geodesic: true
        });

        // Construct a draggable blue triangle with geodesic set to false.
        new google.maps.Polygon({
          map: map,
          paths: blueCoords,
          strokeColor: '#0000FF',
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: '#0000FF',
          fillOpacity: 0.35,
          draggable: false,
          geodesic: false
        });
            }

            function onError(error)
            {
               alert("Getting the error"+error.code + "\nerror mesg :" +error.message);
            }
            </script>

以上是我需要添加的代码,以便从谷歌地图中删除弹出窗口。

请帮帮我。

1 个答案:

答案 0 :(得分:1)

从代码中删除此行:

var infoWindow = new google.maps.InfoWindow({map: map});