2014-04-19 47 views
0

我正在使用socket.io獲取新的經緯度。更新Google地圖標記位置

我有這樣的HTML片段加載在谷歌地圖V3

var socket = io.connect(); 

      socket.on('date', function(data){ 
         $('#date').text(data.date); 

         var locations=[[33.9821000000001,-117.33547],[33.98247,-117.33537],[33.9830000000001,-117.33533]]; 
         var currLatLong = new google.maps.LatLng(33.9821000000001,-117.33547); 
         var mapOptions = { 
         zoom: 14, 
         center: currLatLong 
         } 
         var map = new google.maps.Map(document.getElementById('map'), mapOptions); 


         marker = new google.maps.Marker({ 
         position: new google.maps.LatLng(currLatLong), 
         map: map, 
         title:"a", 
         }); 
         console.log(marker); 

         }); 

但標記,標記不會加載與控制檯沒有給出錯誤或警告。

回答

0

currLatLong已被定義爲LatLng對象。因此,如果地圖加載完美但標記不是,則應該解決問題:

marker = new google.maps.Marker({ 
    position: currLatLong, 
    map: map, 
    title:"a" // also possible typo problem comma 
}); 
+0

我試過了。我記錄了市場對象,而且這個位置似乎是NaN。 –