【问题标题】:Google Map marker errors谷歌地图标记错误
【发布时间】:2021-07-15 09:19:22
【问题描述】:

尝试显示多个标记,但不起作用

(3) InvalidValueError: setTitle: not a string 和多个这些错误 InvalidValueError:setCenter:不是具有有限坐标的 LatLng 或 LatLngLiteral:在属性 lat:NaN 不是可接受的值

<script>
        let cord = []
        $(`.cord`).each(( i , el) => {
            cord[i] = {
               'latitude': Number($(el).data('latitude')),
               'longitude': Number($(el).data('longitude')),
            }
        });
              // Initialize and add the map
              function initMap() {
                let uluru;
                uluru = { lat: -33, lng: 151 };
                 // The map, centered at Uluru
                const map = new google.maps.Map(document.getElementById("map"), {
                    zoom: 4,
                    center: uluru,
                });
                var i = 0;
                while(Object.values(cord).length>i){                    
                // The marker, positioned at Uluru
                const map = new google.maps.Map(document.getElementById("map"), {
                    zoom: 4,
                    center: uluru,
                });
                uluru = { lat: cord[i]['latitude'], lng: cord[i]['longitude'] };
                    const marker = new google.maps.Marker({
                        position: uluru,
                        map: map,
                        title: i,
                        });
                  i++;
                } //loop
              }   //map
    </script>

【问题讨论】:

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


【解决方案1】:

i 不是字符串,它是一个数字。要修复错误,InvalidValueError: setTitle: not a string,请将其更改为 1:

const marker = new google.maps.Marker({
                        position: uluru,
                        map: map,
                        title: "" + i, // Change `i` to a string
                        });

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多