更新Google地图标记位置

时间:2014-04-19 03:22:37

标签: javascript google-maps google-maps-api-3 socket.io

我正在使用socket.io获取新的lat / long。

我有这个html代码段来加载Google Maps 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);

                      });

但是,标记没有加载,控制台没有给出任何错误或警告。

1 个答案:

答案 0 :(得分:0)

currLatLong已定义为LatLng个对象。因此,如果地图加载完美但标记不是,则应解决问题:

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