【问题标题】:Get google map Markers location in Meteor js在 Meteor js 中获取谷歌地图标记位置
【发布时间】:2015-03-27 15:43:10
【问题描述】:

我需要知道如何在 Meteor JS 中获取谷歌地图点的位置。例如,在我的地图中,根据位置纬度和经度显示 10 个指针。当单击标记时,会根据该指针显示位置新窗口(或弹出窗口)

我对此一无所知。所以请建议我为此做些什么?

提前致谢。

【问题讨论】:

标签: meteor


【解决方案1】:

您需要的是InfoWindow,其中有content 选项。

假设你有这个简单的初始化函数

  initializeMap = function() {
     //Common code to init the map.

     //common code to create dynamic markers already give you an answer here
     //https://stackoverflow.com/questions/28424854/how-can-i-create-multiple-markers-on-a-google-map
     //now on the same function lets add this code

   function createMarkers(){

       for(var i = 0 ; i <latLong.length ; i++) {

          //lati and long are declared as global variables.
          lati = latLong[i].lat;
          longi = latLong[i].long;
            var marker = new google.maps.Marker({
               position: new google.maps.LatLng(lati, longi),
               map: map,
               icon: 'http://Yourimagesourcehere'
           });

       //and this is how you call it.
        myInfoWindow(marker2,map,lati,long); 
      }

      //Function to created infoWindows.

    function myInfoWindow(marker2,map,lati,long){

        google.maps.event.addListener(marker2, 'mouseover', function() {
           for(var i=0;i<markerArray.length;i++){
               infoWindow.setContent( 'My lat is ' + lati + "my long is " + longi );
              infoWindow.open(map, marker2);
           }});
        google.maps.event.addListener(marker2, 'mouseout', function() {
           infoWindow.close();
         } 
       }
    }

就像你看到的基于另一个问题How can i create multiple markers on a google map,在这个例子中,我们添加了名为myInfoWindow 的新函数,有4个参数,markermap,以及内容的2个变量(在这种情况下late,long)

如果您对如何初始化地图或代码的外观有疑问,我有这个DEMO,这里是Source Code,只需在infoWindow 函数中添加createMarkers 函数,它应该可以工作. 告诉我是否有效。

【讨论】:

    猜你喜欢
    • 2012-11-26
    • 2019-09-23
    • 2017-12-03
    • 1970-01-01
    • 1970-01-01
    • 2011-01-30
    • 2017-08-08
    • 1970-01-01
    • 2011-04-27
    相关资源
    最近更新 更多