0

我对 Gmpaps 编程中的回调函数有疑问。如果它们在用户从网页上的菜单中选择的特定距离范围内,我会在地图上插入一些兴趣点。我的问题是,是否可以在回调函数中添加一些 javascript 代码,例如通过弹出消息提醒用户等等......

 function callback(response, status) {             
              if (status != google.maps.DistanceMatrixStatus.OK) {
                  alert('Error was: ' + status);
              } else {
                var origins = response.originAddresses;
                var destinations = response.destinationAddresses;
                var icon_2 = mapinfo[address_index_2-1][6];
                var results = response.rows[0].elements;
                     //alert(results[0].distance.value+" <= " +distance_selected);    
                      if(results[0].distance.value <= distance_selected){

                       // HERE I WOULD TO ADD SOME CODE e.g. AN ALERT 

                        geocoder.geocode({'address': mapinfo[address_index_2-1][1]+" "+mapinfo[address_index_2-1][2]+" "+mapinfo[address_index_2-1][3]+" "+mapinfo[address_index_2-1][4]}, 
                        function(results, status) {
                         if (status == google.maps.GeocoderStatus.OK) {
                              bounds.extend(results[0].geometry.location);
                              map.fitBounds(bounds);
                              var marker = new google.maps.Marker({
                              map: map,
                              position: results[0].geometry.location,
                              icon: icon_2
                            });
                              map.setZoom(15);
                              map.setCenter(marker.getPosition());
                              google.maps.event.addListener( marker, 'mouseover', function() {
                                            // Setting the content of the InfoWindow
                                            var filo_content = '<div id="info_map"><h3>' + f_title + '</h3></h5><a href="'+ f_link +'"><h5>Leggi...</h5></a>' + '</div>';                                                
                                            infowindow.setContent(filo_content);                                             
                                            infowindow.open(map, marker);
                                            }); 

                              markersArray.push(marker);   
                          } 
                          else {
                            alert("Geocode was not successful for the following reason: "
                              + status);
                          } // chiusura else

                        });

                      }  //chiusura if controllo distanza

                    }

              } // chiusura callback
4

0 回答 0