更新谷歌地图标记位置

Update Google map marker position

本文关键字:位置 图标 地图 谷歌 更新      更新时间:2023-09-26

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

我有这个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);
                      });

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

currLatLong已定义为LatLng对象。因此,如果地图加载完美,但标记没有加载,这应该可以解决问题:

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