关于flutter插件地图的使用flutter_map

flutter_map

A Dart implementation of Leaflet for Flutter apps.
一个基于leaflet的地图插件,也就是说flutter_map基于的是瓦片地图,那么在兼容性上可以说比较好用了。

横向对比

目前主要的地图插件主要有: flutter_map map_view``amap

map_view

先说下map_view这个插件,这个插件主要是用来展示google map使用。 由于一个我们都知道的原因,我们在使用这个插件的过程中相对比较困难,所以我们可是适当放弃使用这plugin。

flutter_amap

每次看到版本为0.0.1的插件总觉得哪里有问题的,这是高德推出的插件。 高德地图3d flutter组件。

展示原生android、ios高德地图,并与flutter交互。

注意:随着flutter版本的提升, 本项目也会随之更新, 目前这个版本只能在单独的controller或者activity中打开高德地图。 划线部分表示说这个版本还不是很成熟,因此我也不想用

flutter_map

这个插件就是要重点说下的了 ,下面的视频可能需要代理才能光看,示例: 视频 

地址https://pub.dartlang.org/packages/flutter_map
githubhttps://github.com/apptreesoftware/flutter_map 使用:

dependencies:
flutter_map: ^0.3.0

在需要使用的地方根据自动提示添加packages

import 'packages:.....';

需要注意的是可能需要添加LatLng这个包
使用:

Widget build(BuildContext context) {
return new FlutterMap(
options: new MapOptions(
center: new LatLng(51.5, -0.09),//经纬度,注意前后顺序,用于展示中心
zoom: 13.0,
),
layers: [
new TileLayerOptions(
urlTemplate: "https://api.tiles.mapbox.com/v4/"
"{id}/{z}/{x}/{y}@2x.png?access_token={accessToken}",//瓦片地图的URL
additionalOptions: {
'accessToken': '<PUT_ACCESS_TOKEN_HERE>',
'id': 'mapbox.streets',//其他附加内容
},
),
new MarkerLayerOptions(
markers: [
new Marker(//! 地图标记
width: 80.0,
height: 80.0,
point: new LatLng(51.5, -0.09),//经纬度注意顺序
builder: (ctx) =>
new Container(
child: new FlutterLogo(),// 在标记的位置加上标记
),
),
],
),
],
);
}

关于瓦片地图的地址

根据需要将所需要的瓦片地图的地址填入上面的urlTemplate 一下内容摘选于github

TianDiTu: {
Normal: {
Map: "http://t{s}.tianditu.cn/DataServer?T=vec_w&X={x}&Y={y}&L={z}",
Annotion: "http://t{s}.tianditu.cn/DataServer?T=cva_w&X={x}&Y={y}&L={z}"
},
Satellite: {
Map: "http://t{s}.tianditu.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}",
Annotion: "http://t{s}.tianditu.cn/DataServer?T=cia_w&X={x}&Y={y}&L={z}"
},
Terrain: {
Map: "http://t{s}.tianditu.cn/DataServer?T=ter_w&X={x}&Y={y}&L={z}",
Annotion: "http://t{s}.tianditu.cn/DataServer?T=cta_w&X={x}&Y={y}&L={z}"
},
Subdomains: ['0', '1', '2', '3', '4', '5', '6', '7']
}, GaoDe: {
Normal: {
Map: 'http://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'
},
Satellite: {
Map: 'http://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
Annotion: 'http://webst0{s}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}'
},
Subdomains: ["1", "2", "3", "4"]
}, Google: {
Normal: {
Map: "http://www.google.cn/maps/vt?lyrs=m@189&gl=cn&x={x}&y={y}&z={z}"
},
Satellite: {
Map: "http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}"
},
Subdomains: []
}, Geoq: {
Normal: {
Map: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer/tile/{z}/{y}/{x}",
Color: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetColor/MapServer/tile/{z}/{y}/{x}",
PurplishBlue: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}",
Gray: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetGray/MapServer/tile/{z}/{y}/{x}",
Warm: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetWarm/MapServer/tile/{z}/{y}/{x}",
Cold: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetCold/MapServer/tile/{z}/{y}/{x}"
},
Subdomains: [] }
// 当然还有mapbox
"https://api.mapbox.com/v4/"
"{id}/{z}/{x}/{y}@2x.png?access_token={accessToken}"

使用mapbox: 1、创建mapbox账户获取apikey 2、打开leaflet_flutter_example/lib/main.dart粘贴key到:additionalOptionsmap中

使用离线地图

按照本指南获取离线地图块将地图导出后.mbtiles,可以使用mbtilesToPng解压缩/{z}/{x}/{y}.png。将其移动到Assets文件夹并将Asset目录添加到pubspec.yaml。离线地图的最低必填字段为:

new FlutterMap(
options: new MapOptions(
center: new LatLng(56.704173, 11.543808),
minZoom: <offline map minimum zoom>,
maxZoom: <offline map maximum zoom>,
zoom: 13.0,
swPanBoundary: LatLng(56.6877, 11.5089),
nePanBoundary: LatLng(56.7378, 11.6644),
),
layers: [
new TileLayerOptions(
offlineMode: true,
maxZoom: <offline map maximum zoom>,
urlTemplate: "assets/offlineMap/{z}/{x}/{y}.png",
),
],
),

Make sure PanBoundaries are within offline map boundary to stop missing asset errors.
See the flutter_map_example/ folder for a working example

关于flutter插件地图的使用flutter_map的更多相关文章

  1. flutter插件汇总

    audio_recorder: any #录音.播放 flutter_sound: ^#录音 dropdown_menu: ^#下拉菜单 simple_permissions:#权限获取 easy_a ...

  2. Kotlin/Native 用KMM写Flutter插件

    一.用KMM写Flutter插件 Google官方有一个写Flutter例子How to write a Flutter plugin,这里把Google plugin_codelab 例子改成用KM ...

  3. Flutter学习(9)——Flutter插件实现(Flutter调用Android原生

    原文地址: Flutter学习(9)--Flutter插件实现(Flutter调用Android原生) | Stars-One的杂货小窝 最近需要给一个Flutter项目加个apk完整性检测,需要去拿 ...

  4. flutter插件汇总2

    作者:知乎用户链接:https://www.zhihu.com/question/307594373/answer/568969429来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...

  5. Grafana 插件地图Worldmap不显示

    介绍 最近上了ELK 日志分析,想着手看下用户的分布情况,在kibana 中展示用户分布情况是没有问题的,但是索引添加到Granfana 中的话就无法展示. 问题描述 添加ES索引以后,map地图一片 ...

  6. Android studio 使用flutter插件 运行第一个flutter项目 报错 Warning: License for package Android SDK Build-Tools 28.0.3 not accepted.

    在Android studio中新建了flutter项目.运行报错licence not accepted. Warning: License for package Android SDK Buil ...

  7. flutter 高德地图选择位置信息返回

    添加依赖:(注意,作者一直更新维护,请以最新的版本添加) amap_map_fluttify: ^ amap_search_fluttify: ^ 代码实现: import 'package:amap ...

  8. flutter 插件

    flutter_spinkit loading动画

  9. flutter 插件调用callback函数

    dart plugin class TestLib { static MethodChannel _channel = const MethodChannel('test_lib') ..setMet ...

随机推荐

  1. 多媒体文件格式(三):M3U8 格式

    一.M3U8 格式标准介绍 M3U8文件是指UTF-8编码格式的M3U文件.M3U文件是记录了一个索引纯文本文件,打开它时播放软件并不是播放它,而是根据它的索引找到对应的音视频文件的网络地址进行在线播 ...

  2. [Swift]LeetCode149. 直线上最多的点数 | Max Points on a Line

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  3. [Swift]LeetCode971.翻转二叉树以匹配先序遍历 | Flip Binary Tree To Match Preorder Traversal

    Given a binary tree with N nodes, each node has a different value from {1, ..., N}. A node in this b ...

  4. [Swift]LeetCode992. K 个不同整数的子数组 | Subarrays with K Different Integers

    Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A g ...

  5. Linux 工程向 Windows 平台迁移的一些小小 tips

    Linux 工程向 Windows 平台迁移的一些小小 tips VS2013 C++11 Visual Studio 2013 没有做到对 C++11 所有的支持,其中存在的一个特性就是 In-cl ...

  6. linux配置jdk环境变量

    首先在Linux解压后缀为.tar.gz的jdk压缩文件 解压到当前的文件夹 tar -zcvf /root/java/jdk版本编号 指令: cd 目录路径     -> 是进入该目录路径 c ...

  7. SecureCRT 5.2.2版本下载和注册码

    Name: Apollo Interactive Company: Apollo Interactive Serial Number: 03-50-023223License Key: ABMVSR ...

  8. BBS论坛(三十二)

    32.帖子排序功能完成 (1)front_index.html <ul class="post-group-head"> {% if current_sort==1 % ...

  9. 并发编程(四)—— ThreadLocal源码分析及内存泄露预防

    今天我们一起探讨下ThreadLocal的实现原理和源码分析.首先,本文先谈一下对ThreadLocal的理解,然后根据ThreadLocal类的源码分析了其实现原理和使用需要注意的地方,最后给出了两 ...

  10. Python和C++的混合编程(使用Boost编写Python的扩展包)

    想要享受更轻松愉悦的编程,脚本语言是首选.想要更敏捷高效,c++则高山仰止.所以我一直试图在各种通用或者专用的脚本语言中将c++的优势融入其中.原来贡献过一篇<c++和js的混合编程>也是 ...