【问题标题】:Google Maps API missing data from array to markersGoogle Maps API 缺少从数组到标记的数据
【发布时间】:2014-07-02 07:39:27
【问题描述】:

提前道歉,因为这可能看起来有点复杂。

我有一个谷歌地图标记数组,我的标记被添加到称为markersArray

每个标记存储的详细信息是纬度、经度、标题、描述。

使用下面的代码,它会在我的地图上单击标记时运行

google.maps.event.addListener(marker, 'click', function(mll) {
                console.log(mll);
                console.log(markersArray);
                var html= "<div style='color:#000;background-color:#fff;padding:5px;width:150px;'><p></p></div>";
                iw = new google.maps.InfoWindow({content:html});
                iw.open(map,marker);
            });

mll 显示实际标记的日志,markersArray 只显示数组中的标记列表。

我注意到markersArray 中存储的数据并没有被纳入实际标记本身。

有没有办法做到这一点?

如果没有办法使用 Javascript 从markersArray 中找到title,具体取决于您将在下图中看到的latLng 值。

我截取了运行标记单击功能时收到的内容

使用 AngularJS 添加如下标记:

$scope.createmarker = function () {
    geocoder.geocode({
        'address': selectedItem.gps
    }, function (response, status) {
        geocode_results = new Array();
        geocode_results['status'] = status;

        top_location = response[0];
        var lat = Math.round(top_location.geometry.location.lat() * 1000000) / 1000000;
        var lng = Math.round(top_location.geometry.location.lng() * 1000000) / 1000000;
        geocode_results['lat'] = lat;
        geocode_results['lng'] = lng;
        geocode_results['l_type'] = top_location.geometry.location_type;
        marker = new google.maps.Marker({
            icon: mapIcon,
            position: new google.maps.LatLng(lat, lng),
            map: map,
            title: selectedItem.title
        });
        markersArray.push(marker);

        console.log(markersArray);
        console.log(marker);
    });
};

【问题讨论】:

  • 您添加这些属性的部分在哪里?您将每个标记添加到数组的部分在哪里?
  • 如何将标记及其详细信息存储到markersArray
  • 我已经添加了如何将标记添加到数组中
  • 我没有看到标记添加任何描述,但无论如何...您是否尝试记录selectedItem.title?你真的有东西在里面吗?
  • @AntoJurković 谢谢!我想你已经猜到了!我使用的是mll 而不是查看marker 我会给你买一品脱!

标签: javascript google-maps google-maps-api-3 google-maps-markers


【解决方案1】:

使用title 代替mll

google.maps.event.addListener(marker, 'click', function(title) {
                console.log(mll);
                console.log(markersArray);
                var html= "<div style='color:#000;background-color:#fff;padding:5px;width:150px;'><p></p></div>";
                iw = new google.maps.InfoWindow({content:html});
                iw.open(map,marker);
            });

【讨论】:

    猜你喜欢
    • 2014-03-03
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 2014-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多