根据该网站,我正在尝试将Google map 与dart结合使用:
https://pub.dartlang.org/packages/google_maps
我得到这个错误:
Exception: Class 'GElement' has no instance method '[]'.
NoSuchMethodError: method not found: '[]'
Receiver: Instance of 'GElement'
Arguments: ["maps"] (package:google_maps/src/generated/core/base/lat_lng.dart:24)
我的.dart源代码是:
import 'dart:html';
import 'package:polymer/polymer.dart';
import 'package:google_maps/google_maps.dart';
@CustomTag('rifidi-map')
class RifidiMap extends PolymerElement {
RifidiMap.created() : super.created() {
main();
}
void main() {
final mapOptions = new MapOptions()
..zoom = 8
..center = new LatLng(-34.397, 150.644)
..mapTypeId = MapTypeId.ROADMAP
;
final map = new GMap(querySelector("#map_canvas"), mapOptions);
}
}
.HTML文件具有导入以使用脚本:
http://maps.googleapis.com/maps/api/js?sensor=false
我当前使用的版本是:
Dart editor: versión 1.8.3
gogle_maps dart dependency: >=2.0.7 <3.0.0
polymer dart dependency: >=0.15.0 <0.16.0
有没有人可以与我共享工作空间,以了解如何使用Dart实现Google Maps聚合物组件?谢谢
最佳答案
除了在Polymer元素构造函数中进行局部变量初始化外,您不应该执行任何其他操作。请改用生命周期方法。
import 'dart:html';
import 'package:polymer/polymer.dart';
import 'package:google_maps/google_maps.dart';
@CustomTag('rifidi-map')
class RifidiMap extends PolymerElement {
RifidiMap.created() : super.created();
@override
void ready() {
final mapOptions = new MapOptions()
..zoom = 8
..center = new LatLng(-34.397, 150.644)
..mapTypeId = MapTypeId.ROADMAP;
final map = new GMap(querySelector("#map_canvas"), mapOptions);
}
}
我不知道
google_maps
包。它可能仍然不起作用。
关于google-maps - 使用Google Maps的dart类 'GElement'没有实例方法 '[]',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27708975/