问题描述
我正在使用 google_maps_flutter 并想使用自定义标记图标(基于类别,我想使用不同的图标)。
代码
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
pubspec.yaml
google_maps_flutter: ^1.0.6
Maps_view.dart
HashMap bitmaps = new HashMap<String,BitmapDescriptor>();
@override
void initState() {
super.initState();
_createBitMaps();
}
void _createBitMaps() {
List<String> cats = categories; // List of categories
// Based on the category,I want to choose a different asset. The name of the asset and the name of the category are for this reason the same.
for (String cat in cats) {
BitmapDescriptor.fromAssetImage(
ImageConfiguration(size: Size(48,48)),'lib/assets/categorie_icons_location/' + cat + '.png').then((onValue) {
setState(() => bitmaps[cat] = onValue);
}
);
}
}
...
_markers.add(
Marker(
markerId: MarkerId('_' + docs[i]['title'] + '_' + docs[i]['latitude'] + '_' + docs[i]['longitude']),position: LatLng(double.parse(docs[i]['latitude']),double.parse(docs[i]['longitude'])),// Use custom icon based on 'category' (from a firebase document)
icon: bitmaps[docs[i]['category']],infoWindow: InfoWindow(
title: docs[i]['title'],snippet: docs[i]['street'],onTap: () {}
)
)
);
错误
当我启动我的应用程序时出现以下错误:
Cannot enable MyLocation layer as location permissions are not granted
注意
只要我用自定义图标注释代码,我的应用就会完美运行。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)