【问题标题】:Update Google map marker position [duplicate]更新谷歌地图标记位置[重复]
【发布时间】:2014-04-19 03:22:36
【问题描述】:

我正在使用socket.io 来获取新的纬度/经度。

我有这个 html sn-p 来加载谷歌地图 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);

                      });

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 我试过了。我记录了市场对象,位置似乎是 NaN。
    猜你喜欢
    • 2015-10-18
    • 1970-01-01
    • 2018-09-17
    • 1970-01-01
    • 2014-08-27
    • 2019-10-08
    • 2012-02-21
    • 2018-01-30
    • 1970-01-01
    相关资源
    最近更新 更多