0

嗨,大家好我與下面這段代碼的工作,但我不知道是標誌是可能 和我可怎麼辦添加更多的一個標誌,並設置其他DIV顯示此位置。 任何人都知道我能做些什麼,或者給我一個提示谷歌地圖兩個在一個地圖

及其對視覺工作室

angular.module('app', ['onsen']). 
    directive('myMap', function() { 
     // directive link function 
     var link = function (scope, element, attrs) { 
      var map, infoWindow; 
      var markers = []; 

      // map config 
      var mapOptions = { 
       center: new google.maps.LatLng(-29.3130754, -50.8542323), 
       zoom: 11, 
       mapTypeId: google.maps.MapTypeId.ROADMAP, 
       scrollwheel: false 
      }; 

      // init the map 
      function initMap() { 
       if (map === void 0) { 
        map = new google.maps.Map(element[0], mapOptions); 
       } 
      } 

      // place a marker 
      function setMarker(map, position, title, content) { 
       var marker; 
       var markerOptions = { 
        position: position, 
        map: map, 
        title: title, 
        icon: 'images/Maps/blue-dot.png' 
       }; 

       marker = new google.maps.Marker(markerOptions); 
       markers.push(marker); // add marker to array 

       google.maps.event.addListener(marker, 'click', function() { 
        // close window if not undefined 
        if (infoWindow !== void 0) { 
         infoWindow.close(); 
        } 
        // create new window 
        var infoWindowOptions = { 
         content: content 
        }; 
        infoWindow = new google.maps.InfoWindow(infoWindowOptions); 
        infoWindow.open(map, marker); 
       }); 
      } 

      // show the map and place some markers 
      initMap(); 

      setMarker(map, new google.maps.LatLng(-29.3130754, -50.8542323), 'adress'); 

     }; 

     return { 
      restrict: 'A', 
      template: '<div id="gmaps"></div>', 
      replace: true, 
      link: link 
     }; 
    }); 

回答

1

這裏,科爾多瓦的應用是在谷歌地圖中添加多個標記的方式,U盤只需要其中包含數組您所需的緯度經度值。

var myLatLng = {lat: -25.363, lng: 131.044}; 

    var map = new google.maps.Map(document.getElementById('map'), { 
     zoom: 4, 
     center: myLatLng 
    }); 

    var marker = new google.maps.Marker({ 
     position: myLatLng, 
     map: map, 
     title: 'Hello World!' 
    }); 
    var myLatLng1={lat: -25.163, lng: 131.644}; 
    var marker2 = new google.maps.Marker({ 
     position: myLatLng1, 
     map: map, 
     title: 'Hello World!' 
    }); 

你也可以有一個數組,其中包含數據元素conataining latutude和經度值。

 for (var i = 0; i < locations.length; i++) { //Your location contains the lat long position 
     var marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
     map: map, 
     title: 'Hello World!' 
     });