0

如果 javascript 被调用或执行,依赖于什么?准确地说,我有两个以相同方式调用的函数:

[self.mapView stringByEvaluatingJavaScriptFromString:
              [NSString stringWithFormat:@"setMarkerAtPosition(%f,%f)",
                                           latlong.latitude, latlong.longitude]];

[self.mapView stringByEvaluatingJavaScriptFromString:@"test()"];

calculateRoute()被执行而不被执行test()。怎么来的?

function setMarkerAtPosition(lat, long){
    var position = new google.maps.LatLng(lat, long);
    var marker = new google.maps.Marker({position: position, 
                                              map: map, 
                                            title:"Hello World!", 
                                         animation: google.maps.Animation.DROP});
    var content = "Ich bin eine normale Infobox";
    google.maps.event.addListener(marker, 'click', function() {
                              infowindow.setContent(content);
                              infowindow.open(map,marker); 
                              reportClickedMarker();
                              });

}

function test(){
    alert(currentPosition.latitude + ', ' + currentPosition.longitude);
}

谢谢

4

1 回答 1

1

你没有calculateRoute()在任何地方打电话。test()被调用是因为您使用以下方法调用它:

[self.mapView stringByEvaluatingJavaScriptFromString:@"test()"];
于 2012-05-05T19:25:55.757 回答