ios - 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 的正确方法吗?也许我在这样做的路上错了?
解决方案
推荐阅读
- c++ - 在 windows C 程序中使用 popen
- php - 将 target=_blank 添加到 wordpress 简码
- python - 为什么 configparser 必须要读写分离?
- python-3.x - Python Tkinter Notebook 使用“.place”定位小部件
- python - Python中的单元测试类
- python - 无法将 iob 转换为 spaCy 二进制格式
- sql - 修改存储过程返回数据
- nginx - 允许 api.glossgenius.com 的 CORS
- python - 如何使用网关 api 信息检查元素?
- jquery - 生成自动标题的功能