2014-04-19 252 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。 –

相关问题