首页 > 解决方案 > Google Maps Flutter 自定义标记未显示

问题描述

因为我在使用谷歌地图和位图描述符时遇到了问题,所以我尝试在加载地图之前预加载图标,如下所示:

Widget preloadPinsAndLoadSearchMap() {
  final config = ImageConfiguration(size: Size(48, 48));
  final activePin = 'assets/active-pin.png';
  final neutralPin = 'assets/neutral-pin.png';
  final home = 'assets/home-map.png';
  return FutureBuilder(
    future: Future.wait([
      BitmapDescriptor.fromAssetImage(config, activePin),
      BitmapDescriptor.fromAssetImage(config, neutralPin),
      BitmapDescriptor.fromAssetImage(config, home),
    ]),
    builder: (context, snapshot) {
      if (snapshot.connectionState == ConnectionState.done) {
        return SearchMap(pins: snapshot.data);
      } else {
        return Container();
      }
    },
  );
}

以及 SearchMap 和标记:

// Each Marker is produced like this:
Marker createMarker(dynamic seller) {
  return Marker(
    markerId: MarkerId(seller.id),
    position: LatLng(seller.latitude, seller.longitude),
    onTap: () => onMarkerTap(seller),
    // The icons are coming from the FutureBuilder.
    icon: isActive ? activePin : neutralPin,
  );
}

class SearchMap extends StatelessWidget {
  Widget build(BuildContext context) {
    final paris = initialPosition ??
      LatLng(parisPosition.latitude, parisPosition.longitude);
    return GoogleMap(
      myLocationButtonEnabled: false,
      zoomControlsEnabled: false,
      compassEnabled: false,
      mapType: MapType.normal,
      markers: markers,
      initialCameraPosition: CameraPosition(target: paris, zoom: 15),
      onMapCreated: onMapCreated,
      onTap: (obj) => print(obj),
    );
  }
}

令人高兴的是,它在我的设备上运行良好,无论是 iOS 还是 Android。但是在我的审阅者设备上,图标只是没有显示。它是处理 BitmapDescriptor 的正确方法吗?也许我在这样做的路上错了?

标签: iosfluttergoogle-maps

解决方案


推荐阅读