Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In the Google Maps API v3 they have stated that we need to do this to open the infowindow when the marker gets clicked:

google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
});

Now I am trying to duplicate this in dart using the js library. So far I have something like this:

final google_maps = context['google']['maps'];

var myLatlng = [43.5, -6.5];
var center = new JsObject(google_maps['LatLng'], myLatlng);

var mapTypeId = google_maps['MapTypeId']['ROADMAP'];

var mapOptions = new JsObject.jsify({
  "center": center,
  "zoom": 8,
  "mapTypeId": mapTypeId
});

var map = new JsObject(google_maps['Map'], [querySelector('#map-canvas'), mapOptions]);

var marker = new JsObject(google_maps['Marker'], [new JsObject.jsify({
  'position': center,
  'map': map,
  'title': 'Hello World!'
})]);

var tooltip = '<div id="content">Info window coontent</div>';

var infowindow = new JsObject(google_maps['InfoWindow'], [new JsObject.jsify({
"content": tooltip
})]);


google_maps['event'].callMethod('addListener', [marker, 'click', () {
  infowindow.callMethod('open',[map,marker]);
}]);

The issue is that I set the 'addListener' method through google_maps['event'], but when I click the marker, I get a NoSuchMethodError:

Closure call with mismatched arguments: function 'call'

NoSuchMethodError: incorrect number of arguments passed to method named 'call'
Receiver: Closure: () => dynamic
Tried calling: call(Instance of 'JsObject')
Found: call()

I am aware that there is a google_maps dart package, but I want the interact with the javascript api using dart's js library.

Thanks in advance.

share|improve this question
    
Why don't you want to use the google_maps package ? It use dart:js under the cover and provide a typed API much simpler to use than directly using dart:js. –  Alexandre Ardhuin Aug 29 '14 at 19:31
    
@AlexandreArdhuin, not that I don't want to use it, the opposite. It's that I was starting to look into dart and google maps and when I couldn't make this bit work I precisely "found" that package. I'm using it actually but I wanted to know what I was doing wrong and that's why I asked this and the comment was for avoiding answers telling me about the package –  mitomed Aug 30 '14 at 19:34

1 Answer 1

up vote 6 down vote accepted

Your closure has zero arguments.

() {
   infowindow.callMethod('open',[map,marker]);
}

You just have to give it an argument as stated in the error message:

(event) {
   infowindow.callMethod('open',[map,marker]);
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.