使用FLUTTER_MAP时图像数据无效

k4ymrczo  于 2023-06-24  发布在  Flutter
关注(0)|答案(1)|浏览(136)
class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FutureBuilder(
        future: acquireCurrentLocation(),
        builder: (BuildContext context, AsyncSnapshot<LatLng?> snapshot) {
          if (snapshot.hasData) {
            print(snapshot.data);
            print(snapshot.data!.latitude);
            return FlutterMap(
              options: MapOptions(
                center:
                    LatLng(snapshot.data!.latitude, snapshot.data!.longitude),
                zoom: 13.0,
              ),
              layers: [
                TileLayerOptions(
                    urlTemplate:
                        "cc",
                    additionalOptions: {
                      'accessToken':
                          'cc',
                      'id': 'cc',
                    }),
                MarkerLayerOptions(
                  markers: [
                    Marker(
                      width: 80.0,
                      height: 80.0,
                      point: LatLng(
                          snapshot.data!.latitude, snapshot.data!.longitude),
                      builder: (ctx) => Container(
                        child: IconButton(
                          icon: Icon(Icons.location_on),
                          onPressed: null,
                          color: Colors.red,
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            );
          } else if (!snapshot.hasData) {
            return Center(
              child: CircularProgressIndicator(),
            );
          } else {
            return Container();
          }
        },
      ),
    );
  }
}

我得到错误无效的图像数据,我已经输入了正确的令牌,URL在我的工作文件。有人能告诉我我做错了什么或我如何解决这个错误吗?我试过在模拟器和真实的设备中运行它,调试时的错误显示在pain.dart文件中,在最有可能的未来函数声明时(错误!=null)

w1jd8yoj

w1jd8yoj1#

而不是像你正在做的那样导出,尝试将其导出为“Carto”,然后使用他们给予你的模板作为urlTemplate,私钥作为additionalOptions。这是flutter_map使用的格式。

相关问题