打印/下载
案例
import 'package:flutter/material.dart';
import 'package:webmis/library/inc/time-set.dart';
import 'package:webmis/library/plus/map-geolocation.dart';
import 'package:webmis/library/plus/map-marker.dart';

class Demo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => DemoState();
}
class DemoState extends State<Demo> {

  Map<String,dynamic> _location;
  var _mapController;

  /* 构造函数 */
  @override
  void initState() {
    super.initState();
    // 定位
    _getLocation();
  }

  /* 销毁 */
  @override
  void dispose(){
    super.dispose();
    MapGeolocation.dispose();
  }

  /* 定位 */
  Future<void> _getLocation({int time: 3000}) async {
    Map res = await MapGeolocation.fetch(context);
    if(res['longitude']>0) setState(()=> _location=res );
    setTimeout((){
      if(_location!=null && _mapController!=null){
        _mapController.setCenter([_location['longitude'],_location['latitude']]);
        _mapController.setZoom(18);
        _mapController.addMarker([
          {'title':'我','position':[_location['longitude'],_location['latitude']],'img':'https://webmis.vip/themes/home/img/logo.svg'},
        ]);
      }
    },time);
  }

  /* Widget */
  @override
  // ignore: must_call_super
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: 300,
        child: MapMarker(
          controller: (res)=>_mapController=res,
          javascript: [
            {'name':'getLocation','msg':(res)=>_getLocation(time: 16)},
          ],
        ),
      ),
    );
  }

}
{{copy}}