This is a low version of the map dependency, to special functions also please use the latest version, this is for reference only

This is a low version of the map dependency, to special functions also please use the latest version, this is for reference only

This is a low version of the map dependency, to special functions also please use the latest version, this is for reference only

Rely on:

This is correct map + location + permissions

  amap_base_map: 04.4.+ 1amap_location:
  permission_handler: ^ 3. 0. 0
Copy the code

Reference:

Blog.csdn.net/ivy_doudou/…

Access configuration

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <application android:name="io.flutter.app.FlutterApplication" android:label="flutter_01" android:icon="@mipmap/ic_launcher"> <meta-data Android :name="com.amap.api.v2.apikey" Android :value=" API key"/> </application>Copy the code

Pub. Flutter – IO. Cn/packages/am…

Blog.csdn.net/u014370269/…

Javascript.ctolib.com/boomcx-amap…

Android and ios have different keys

Is likely to change in the main AMap. Init (‘ b905201aabd1c690b38135283bb69d62 ‘);

Steps:

1. Amap_base_map has an error, and you need to modify the meta-code with a comment. map/android/src/main/kotlin/me/yohom/amapbasemap/map/MapHandlers.kt

object OpenOfflineManager : MapMethodHandler {

    override fun with(map: AMap): MapMethodHandler {
        return this
    }
    // Error code comment
    override fun onMethodCall(methodCall: MethodCall, methodResult: MethodChannel.Result){
    }

    /*override fun onMethodCall(p0: MethodCall? , p1: MethodChannel.Result?) { registrar.activity().startActivity( Intent(AMapBaseMapPlugin.registrar.activity(), OfflineMapActivity::class.java) ) }*/
}
Copy the code

2.code

import 'package:flutter/material.dart';
import 'package:amap_base_map/amap_base_map.dart'; // amap_base_map import'package:amap_location/amap_location.dart';
import 'package:fluttertoast/fluttertoast.dart'; // Prompt box import'package:permission_handler/permission_handler.dart'; /** * ShowMapScreen * Map zooming * Annotation * use ShowMapScreen(25.1298300890, 113.377829), */ class ShowMapScreen extends StatefulWidget { @override _ShowMapScreenState createState() => _ShowMapScreenState(); } class _ShowMapScreenState extends State<ShowMapScreen> { AMapController _controller; Static double lAT = 25.129830089063844; Static double LNG = 113.37782986111111; var lating =LatLng(lat,lng); // Set default values to prevent accidents @override voidinitState() {
    super.initState();
    _getLocation();
  }

  @override
  void dispose() {
    _controller.dispose();
        AMapLocationClient.shutdown();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Builder(
        builder: (context) {
//          Future.delayed(Duration(milliseconds: 1000));
          returnContainer( height: 300, child: Stack( children: <Widget>[ AMapView( onAMapViewCreated: (controller) {_controller = controller; _controller. MapClickedEvent. Listen ((it) {/ / / / processing click events to empty tag _controller. ClearMarkers (); / / punctuation _controller. AddMarker (MarkerOptions (position: it,));}); _controller. ShowMyLocation (true); / / the default display their _controller. SetMyLocationStyle (MyLocationStyle (strokeWidth: 0.0, showMyLocation:true, / / positioning themselves, the above is useful, I don't know this have a purpose, but still with myLocationType: 5, / / orientation, but does not move to the center of the map, anchor point in accordance with the direction of equipment, and will follow equipment mobile interval: 1000, / / 1 s positioning a)); }, amapOptions: AMapOptions( zoomControlsEnabled:false,
                      compassEnabled: true// zoomControlsEnabled:true// Allow zooming logoPosition: 2,// Logo in the lower right corner of the map Camera: CameraPosition(target: lating, zoom: 18,),),), top: Child: 10, 150, right: InkWell (onTap: () is async {/ / for positioning the var geting = await AMapLocationClient. GetLocation (true);
                        setState(() { lng = geting.longitude; lat = geting.latitude; lating = LatLng(lat, lng); }); // Move the specified LatLng to the center _controller.changelatlng (lating); }, child: Container( alignment: Alignment.center, height: 50, width: 50, color: Colors.indigoAccent, child: Text('personal'),// jump to personal position),),),],); },),); Void _getLocation() async {// Apply for permission Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler() .requestPermissions([PermissionGroup.location]); PermissionStatus Permission = await PermissionHandler().checkpermissionStatus (permissiongroup.location);if(permission = = PermissionStatus. Granted) {/ / authorization required to start the system success - "/ / options AMapLocationClient. Startup (new AMapLocationOption ( desiredAccuracy: CLLocationAccuracy.kCLLocationAccuracyHundredMeters)); / / get the current position of var geting = await AMapLocationClient. GetLocation (true);
      setState(() { lng = geting.longitude; lat = geting.latitude; lating = LatLng(lat, lng); _controller.changeLatLng(lating); // final nextLatLng = LatLng(lat, lng); }); / / location change monitoring AMapLocationClient. OnLocationUpate. Listen (AMapLocation (loc) {/ /print("$lng $lat");
        if(! mounted)return;
        setState(() { lng=loc.longitude; lat=loc.latitude; lating = LatLng(lat,lng); }); }); / / start listening position change AMapLocationClient. StartLocation (); }else {
      getFloat('Please turn on GPS and allow location permission'); }} // float (String text) {fluttertoast.showtoast (MSG: text, toastLength: toast.length_short, gravity: CENTER, timeInSecForIos: 2, fontSize: 16.0); }}Copy the code

Use the ShowMapScreen ()

import 'package:flutter/material.dart';

import 'ShowMapScreen.dart';

class NewPage extends StatefulWidget {
  @override
  _NewPageState createState() => _NewPageState();
}

class _NewPageState extends State<NewPage> {
  @override
  Widget build(BuildContext context) {
    returnContainer( child: SingleChildScrollView( child: Column(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[ Container( width: MediaQuery.of(context).size.width, height: 200, child: ShowMapScreen()), ]), )); }}Copy the code

Add default Positioning

import 'package:flutter/material.dart';
import 'package:amap_base_map/amap_base_map.dart'; // amap_base_map import'package:amap_location/amap_location.dart';
import 'package:fluttertoast/fluttertoast.dart'; // Prompt box import'package:permission_handler/permission_handler.dart'; /** * ShowMapScreen * Map zooming * Annotation * use ShowMapScreen(25.1298300890, 113.377829), */ class ShowMapScreen extends StatefulWidget {final Lat; // Longitude - final LNG; [this. / / latitude ShowMapScreen (lat, enclosing LNG]); @override _ShowMapScreenState createState() => _ShowMapScreenState(); } class _ShowMapScreenState extends State<ShowMapScreen> { AMapController _controller; Static double lAT = 25.129830089063844; Static double LNG = 113.37782986111111; var lating =LatLng(lat,lng); Var nating = LatLng (28.1298, 113.3778); // Override voidinitState() {
    super.initState();
    _getLocation();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Builder(
        builder: (context) {
//          Future.delayed(Duration(milliseconds: 1000));
          returnContainer( height: 300, child: Stack( children: <Widget>[ AMapView( onAMapViewCreated: (controller) {_controller = controller; _controller. MapClickedEvent. Listen ((it) {/ / / / processing click events to empty tag _controller. ClearMarkers (); / / punctuation _controller. AddMarker (MarkerOptions (position: it,));}); _controller. ShowMyLocation (true); / / the default display their _controller. SetMyLocationStyle (MyLocationStyle (strokeWidth: 0.0, showMyLocation:true, / / positioning themselves, the above is useful, I don't know this have a purpose, but still with myLocationType: 5, / / orientation, but does not move to the center of the map, anchor point in accordance with the direction of equipment, and will follow equipment mobile interval: 1000, / / 1 s positioning a)); }, amapOptions: AMapOptions( zoomControlsEnabled:false,
                      compassEnabled: true// zoomControlsEnabled:true// Allow zooming logoPosition: 2,// Logo in the lower right corner of the map Camera: CameraPosition(target: lating, zoom: 18,),),), top: Child: 10, 150, right: InkWell (onTap: () is async {/ / for positioning the var geting = await AMapLocationClient. GetLocation (true);
                        setState(() { lng = geting.longitude; lat = geting.latitude; lating = LatLng(lat, lng); }); // Move the specified LatLng to the center _controller.changelatlng (lating); }, child: Container( alignment: Alignment.center, height: 50, width: 50, color: Colors.indigoAccent, child: Text('personal'), ), ), ), Positioned( top: 100, right: 10, child: InkWell( onTap: () {// Move the specified LatLng to the center _controller.changelatlng (nating); _controller.addMarker(MarkerOptions( position: nating, )); }, child: Container( alignment: Alignment.center, height: 50, width: 50, decoration: BoxDecoration( color: Colors.indigoAccent, border: Border(bottom:BorderSide( width: 1,color: Color(0xff000) )) ), // child: Icon(Icons.add), child: Text('host'(() [() [() [() [() },),); } _getLocation() async {checkPersmission(); Void checkPersmission() async {// Apply for permission Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler() .requestPermissions([PermissionGroup.location]); PermissionStatus Permission = await PermissionHandler().checkpermissionStatus (permissiongroup.location);if(permission = = PermissionStatus. Granted) {/ / authorization required to start the system success - "/ / options AMapLocationClient. Startup (new AMapLocationOption ( desiredAccuracy: CLLocationAccuracy.kCLLocationAccuracyHundredMeters)); // If there is an incoming latitude and longitudeif(widget.lat! =null){ nating = LatLng(widget.lat?? 28.1298, the widget. The LNG?? 113.3778); _controller.changelatlng (nating); _controller.addMarker(MarkerOptions( position: nating, )); }else{/ / get the current position of var geting = await AMapLocationClient. GetLocation (true);
      setState(() { lng = geting.longitude; lat = geting.latitude; lating = LatLng(lat, lng); _controller.changeLatLng(lating); // final nextLatLng = LatLng(lat, lng); }); / / location change monitoring AMapLocationClient. OnLocationUpate. Listen (AMapLocation (loc) {/ /print("$lng $lat");
        if(! mounted)return;
        setState(() { lng=loc.longitude; lat=loc.latitude; lating = LatLng(lat,lng); }); }); / / start listening position change AMapLocationClient. StartLocation (); }}else {
      getFloat('Please turn on GPS and allow location permission'); }} // float (String text) {fluttertoast.showtoast (MSG: text, toastLength: toast.length_short, gravity: CENTER, timeInSecForIos: 2, fontSize: 16.0); }}Copy the code