Google maps 谷歌地图API:可以在信息窗口中搜索文本吗?

Google maps 谷歌地图API:可以在信息窗口中搜索文本吗?,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我目前正在开发一个应用程序,根据用户的帖子,在谷歌地图上的infowindows中放置各种标记。我还包括了地理编码,这样用户就可以改变他们的位置,查看任何区域的标记/帖子 我想做的是让用户通过一个表单搜索信息窗口中的文本信息,然后地图会显示包含该文本窗口的标记。我已经搜索了API,但是我没有看到提到这个功能,尽管它看起来应该是可以实现的 任何关于如何实现这一点的见解或信息都将不胜感激 以下是应用程序中的当前代码: function mainGeo() { if (navigator.g

我目前正在开发一个应用程序,根据用户的帖子,在谷歌地图上的infowindows中放置各种标记。我还包括了地理编码,这样用户就可以改变他们的位置,查看任何区域的标记/帖子

我想做的是让用户通过一个表单搜索信息窗口中的文本信息,然后地图会显示包含该文本窗口的标记。我已经搜索了API,但是我没有看到提到这个功能,尽管它看起来应该是可以实现的

任何关于如何实现这一点的见解或信息都将不胜感激

以下是应用程序中的当前代码:

function mainGeo()
{
     if (navigator.geolocation) 
        {
          navigator.geolocation.getCurrentPosition( mainMap, error, {maximumAge: 30000, timeout: 10000, enableHighAccuracy: true} );
    }
    else
    {
          alert("Sorry, but it looks like your browser does not support geolocation.");
    }
}


var stories = {{storyJson|safe}};
var geocoder;
var map;


function loadMarkers(stories){
    for (i=0;i<stories.length;i++) {
        var story = stories[i];

        (function(story) {
            var pinColor = "69f2ff";
                var pinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=S|" + pinColor,
                    new google.maps.Size(21, 34),
                    new google.maps.Point(0,0),
                    new google.maps.Point(10, 34));
          var point = new google.maps.LatLng(story.latitude, story.longitude);
          var marker = new google.maps.Marker({position: point, map: map, icon: pinImage});
          var infowindow = new google.maps.InfoWindow({
            content: '<div >'+
                '<div >'+
                '</div>'+
                '<h2 class="firstHeading">'+story.headline+'</h2>'+
                '<div>'+
                '<p>'+story.author+'</p>'+
                '<p>'+story.city+'</p>'+
                '<p>'+story.topic+'</p>'+
                '<p>'+story.date+'</p>'+
                '<p>'+story.copy+'</p>'+
                '<p><a href='+story.url+'>Click to read story</a></p>'+
                '</div>'+
                '</div>'

          });
          google.maps.event.addListener(marker, 'click', function() {
            infowindow.open(map,this);
          });
        })(story);
    }
}



 function mainMap(position)
 {
       geocoder = new google.maps.Geocoder();
       // Define the coordinates as a Google Maps LatLng Object
       var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);


       // Prepare the map options
       var mapOptions =
      {
                  zoom: 15,
                  center: coords,
                  mapTypeControl: false,
                  navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
                  mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        // Create the map, and place it in the map_canvas div
        map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

        // Place the initial marker
        var marker = new google.maps.Marker({
                  position: coords,
                  map: map,
                  title: "Your current location!"
        });

        loadMarkers(stories);

    }


  function codeAddress() {
    var address = document.getElementById("address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }


function error() {
    alert("You have refused to display your location. You will not be able to submit stories.");
    }

mainGeo();
函数mainGeo()
{
if(导航器.地理位置)
{
getCurrentPosition(mainMap,错误,{maximumAge:30000,超时:10000,enableHighAccurance:true});
}
其他的
{
警报(“抱歉,您的浏览器似乎不支持地理位置。”);
}
}
var stories={{storyJson | safe}};
var地理编码器;
var映射;
函数加载标记(故事){
对于(i=0;i
  • 创建三个空数组(例如,
    标记
    信息窗口
    ,和
    匹配
  • 实例化标记时,通过
    markers
    数组中的索引引用标记(例如,
    markers[i]=marker
  • 在实例化infowindow时,通过
    infowindows
    数组中的索引引用其内容(例如,
    infowindows[i]=htmltext
    [或存储内容的任何变量名)
  • infowindows
    数组中搜索字符串,在
    matches
    数组中存储包含该字符串的项目的索引,然后在
    matches
    数组中使用for循环来添加
    markers
    数组中的标记(基于
    matches
    数组的索引值)

  • 谢谢。不确定在当前代码中的确切位置。