首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >参数类型'LatLng‘不能分配给参数类型'LatLng?’

参数类型'LatLng‘不能分配给参数类型'LatLng?’
EN

Stack Overflow用户
提问于 2022-08-13 05:19:04
回答 2查看 422关注 0票数 0

当在MapOptions-> Center中使用地图时,当输入lat和液化天然气时,参数类型'LatLng‘不能分配给参数类型'LatLng?’。

代码语言:javascript
复制
class MapsView extends HookConsumerWidget {
  MapsView({Key? key}) : super(key: key);
   final MapController _mapController=MapController();

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return FlutterMap(
      options: MapOptions(
       center: LatLng(51.509364, -0.128928),
        zoom: 9.2,
      ),
      layers: [
        TileLayerOptions(
          urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
          userAgentPackageName: 'com.example.app',
        ),
      ],
      nonRotatedChildren: [
        AttributionWidget.defaultWidget(
          source: 'OpenStreetMap contributors',
          onSourceTapped: null,
        ),
      ],
    );
  }

  }

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-08-13 05:41:20

代码语言:javascript
复制
import 'package:latlong2/latlong.dart';
import 'package:flutter_map/flutter_map.dart';
 class MapsView extends HookConsumerWidget {
  MapsView({Key? key}) : super(key: key);
 final MapController _mapController=MapController();

 @override
  Widget build(BuildContext context, WidgetRef ref) {
return FlutterMap(
  options: MapOptions(
   center: LatLng(51.509364, -0.128928),
    zoom: 9.2,
  ),
  layers: [
    TileLayerOptions(
      urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
      userAgentPackageName: 'com.example.app',
    ),
  ],
  nonRotatedChildren: [
    AttributionWidget.defaultWidget(
      source: 'OpenStreetMap contributors',
      onSourceTapped: null,
    ),
  ],
);
}

 }

'package:latlong2/latlong.dart导入

在包中没有导出,所以您必须手动导入它才能在其中赋值。

票数 2
EN

Stack Overflow用户

发布于 2022-08-13 05:41:54

我认为你不需要使用latLng2

依赖关系: latlong2:^0.8.0

代码语言:javascript
复制
import 'package:latlong2/latlong.dart' as latLng;

FlutterMap(
      options: MapOptions(
       center: latLng.LatLng(51.509364, -0.128928),
        zoom: 9.2,
      ),
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73341777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档