문제

이 코드를 사용해

for(i=0; i<num ;i++)
{
    points.push([lats[i], lngs[i]]);

    if(i==0) str = 'S';
    else if(i==num-1) str = 'E';
    else str = '';

    var marker = new nokia.maps.map.Marker(
            [lats[i], lngs[i]],
            {
                    title: str,
                    visibility: true,
                    icon: img,
                    anchor: new nokia.maps.util.Point(5, 5)
            });
    marker.addListener('click', function(evt){
            $('.loc').html(times[i]);
    });
    map.objects.add(marker);
}
.

그러나 단지 클릭 이벤트를 실행하지 않습니다.코드에 문제가 있습니까?

latslngstimes가 정의되고 points가 나중에 사용됩니다.

편집 :

문제 해결.아래에 답변을 참조하십시오.

도움이 되었습니까?

해결책

문제가 라인과 함께있는 것처럼 보입니다.

$('.loc').html(times[i]);
. 마커 리스너 내의

.이벤트는 해고되면 배열 요소에 액세스 할 수 없으므로 실패합니다.마커에 속성을 추가하고 그림과 같이 액세스해야합니다.

var marker = new nokia.maps.map.Marker(
            [lats[i], lngs[i]],
            {
                    title: str,
                    visibility: true,
                    icon: img,
                    anchor: new nokia.maps.util.Point(29, 71),
                    $html : times[i]
            });
    marker.addListener('click', function(evt){
            //$('.loc').html(times[i]); 
           alert (evt.target.$html);
    });
.

다음을 시도하십시오 (물론 자신의 앱 ID와 토큰) :

<!DOCTYPE HTML SYSTEM>
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9" />
        <script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.2.3/jsl.js"></script>


        <style type="text/css">

            html {
                overflow:hidden;
            }

            body {
                margin: 0;
                padding: 0;
                overflow: hidden;
                width: 100%;
                height: 100%;
                position: absolute;
            }

            #mapContainer {
                width:100%;
                height: 100%;
                left: 0;
                top: 0;
                position: absolute;
            }

 </style>
    </head>
    <body>
        <div id="mapContainer"></div>
        <script type="text/javascript">

            nokia.Settings.set( "appId", "YOUR APP ID GOES HERE"); 
            nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");

var mapContainer = document.getElementById("mapContainer");


var DefaultLatitude = 52.516237;
var DefaultLongitude = 13.377686;
var defaultZoomLevel = 16;

var mapOptions =
{
    baseMapType: nokia.maps.map.Display.NORMAL,
    center: new nokia.maps.geo.Coordinate(DefaultLatitude, DefaultLongitude),    
    zoomLevel: defaultZoomLevel,
    components: [
        new nokia.maps.map.component.ZoomBar(),
        new nokia.maps.map.component.Behavior(),
        new nokia.maps.map.component.Overview(),
        new nokia.maps.map.component.ScaleBar(),
        new nokia.maps.map.component.ContextMenu()
    ]
};

  var map = new nokia.maps.map.Display(mapContainer, mapOptions);



var str ="";
var img = "http://api.maps.nokia.com/en/playground/examples/maps/res/markerHouse.png";
var points= new Array();
var lats = new Array();
var lngs = new Array();
var times = new Array();
var num;

lats[0] = 52.516237;
lngs[0] = 13.377686;
times[0] = "brandenburg gate";
num = 1;
for(var i=0; i<num ;i++)
{
    points.push([lats[i], lngs[i]]);

    if(i==0) str = 'S';
    else if(i==num-1) str = 'E';
    else str = '';

    var marker = new nokia.maps.map.Marker(
            [lats[i], lngs[i]],
            {
                    title: str,
                    visibility: true,
                    icon: img,
                    anchor: new nokia.maps.util.Point(29, 71),
                    $html : times[i]
            });
    marker.addListener('click', function(evt){
            //$('.loc').html(times[i]); 
           alert (evt.target.$html);
    });
    map.objects.add(marker);
}

 </script>
    </body>
</html>
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top