Giter VIP home page Giter VIP logo

ai_amap's Introduction

ai_amap

totem


English Document 中文文档
Plugin Pub Points Popularity Likes
ai_amap pub package pub points popularity likes

Effect

iOS-map Android-map
ios android
:- :-
web-map
web
:-

1.安装

使用当前包作为依赖库

1. 依赖此库

在文件 'pubspec.yaml' 中添加

Plugin Pub Points Popularity Likes
ai_amap pub package pub points popularity likes

dependencies:

  ai_amap: ^version

或者以下方式依赖

dependencies:

  # ai_amap package.
  ai_amap:
    git:
      url: https://github.com/pdliuw/ai_amap.git

2. 安装此库

你可以通过下面的命令行来安装此库


$ flutter pub get


你也可以通过项目开发工具通过可视化操作来执行上述步骤

3. 导入此库

现在,在你的Dart编辑代码中,你可以使用:


import 'package:ai_amap/ai_amap.dart';

2.使用

使用'地图'需要动态申请权限,动态权限推荐:permission_handler

配置权限

Android

    <!--
    地图SDK(包含其搜索功能)需要的基础权限
    -->

    <!--允许程序打开网络套接字-->
    <uses-permission android:name="android.permission.INTERNET" />
    <!--允许程序设置内置sd卡的写权限-->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!--允许程序获取网络状态-->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!--允许程序访问WiFi网络信息-->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <!--允许程序读写手机状态和身份-->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <!--允许程序访问CellID或WiFi热点来获取粗略的位置-->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <!--
    地图定位需要的权限
    -->

    <!--用于进行网络定位-->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <!--用于访问GPS定位-->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <!--用于获取运营商信息,用于支持提供运营商信息相关的接口-->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <!--用于访问wifi网络信息,wifi信息会用于进行网络定位-->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <!--用于获取wifi的获取权限,wifi信息会用来进行网络定位-->
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <!--用于访问网络,网络定位需要上网-->
    <uses-permission android:name="android.permission.INTERNET"/>
    <!--用于读取手机当前的状态-->
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <!--用于写入缓存数据到扩展存储卡-->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <!--用于申请调用A-GPS模块-->
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>

    <!--
    导航所需权限
    -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />


    <application>
    
    ...    

        <meta-data
            android:name="com.amap.api.v2.apikey"
            android:value="${apiKey}" />
        <!--
        https://lbs.amap.com/api/android-location-sdk/guide/android-location/getlocation
        (请在application标签中声明service组件,每个app拥有自己单独的定位service。)
        -->
        <service android:name="com.amap.api.location.APSService"></service>

        <!--
        地图导航组件
        -->
        <activity android:name="com.amap.api.navi.AmapRouteActivity"
            android:theme="@android:style/Theme.NoTitleBar"
            android:configChanges="orientation|keyboardHidden|screenSize" />

    </application>

iOS

	<key>NSFileProviderPresenceUsageDescription</key>
	<string>使用时允许访问文件</string>
	<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
	<string>始终允许定位(提高后台定位准确率)</string>
	<key>NSLocationAlwaysUsageDescription</key>
	<string>使用时始终允许定位</string>
	<key>NSLocationWhenInUseUsageDescription</key>
	<string>使用时允许定位</string>


** 为提高iOS定位成功率,请打开-->'Background Modes' --> 勾选☑ ️'Location Updates' **

iOS支持PlatformView配置:

	
    <key>io.flutter.embedded_views_preview</key>
    <true/>
    
web
    
    <script src="https://webapi.amap.com/loader.js" type="text/javascript"></script>
    
    

1.使用'地图组件'的地方中:

    //map widget
    _aMapWidget = AiAMapLocationPlatformWidget(
      platformWidgetController: _locationController,
    );

  • 2、使用地图Controller

    _locationController = AiAMapLocationPlatformWidgetController(
      locationResultCallback:
          (AiAMapLocationResult locationResult, bool isSuccess) {
        setState(() {
          _currentState = "定位:$isSuccess";
        });

        if (locationResult.haveAddress()) {
          _locationController.stopLocation();

          setState(() {
            if (widget._locationResultCallback != null) {
              widget._locationResultCallback(locationResult, isSuccess);
            }
            _locationAddress = locationResult.address;
          });

        }
      },
      platformViewCreatedCallback: (int id) {
        setState(() {
          //1、ApiKey
          AiAMapLocationPlatformWidgetController.setApiKey(
              apiKey: "$_yourPrimaryKey");
          //2、初始化定位服务
          _locationController..recreateLocationService();
          _locationController.startLocation();
          setState(() {
            _currentState = "开始定位";
          });
        });
      },

2.使用'定位服务'的地方中:


      @override
      void initState() {
        super.initState();
    
        _locationController = AiAMapLocationController(
          locationResultCallback: (result, successful) {
            if (result.haveAddress()) {
              _stopLocation();
              setState(() {
                _locationAddress = result.address;
              });
            }
          },
        );
    
        WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
          //1、ApiKey
          AiAMapLocationController.setApiKey(
              apiKey: "${GlobalConfig.AMAP_KEY}");
          _startLocation();
        });
      }



      void _startLocation() {
        _locationController.startLocation();
        
      }

        
      void _stopLocation() {
        _locationController.stopLocation();

      }
    

LICENSE

BSD 3-Clause License

Copyright (c) 2020, pdliuw
All rights reserved.

ai_amap's People

Contributors

nonnonnon avatar pdliuw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ai_amap's Issues

空安全

什么时候可以支持空安全呀

关于1.1.0 IOS 提示 type 'AiAMapLocationPlatformView' does not conform to protocol 'AMapGeoFenceManagerDelegate'

日志如下:
/Users/zhangzhigang/.pub-cache/hosted/pub.flutter-io.cn/ai_amap-1.1.0/ios/Classes/AiAMapLocationPlatformView.swift:17:7: error: type 'AiAMapLocationPlatformView' does not conform to protocol 'AMapGeoFenceManagerDelegate'
class AiAMapLocationPlatformView:NSObject,FlutterPlatformView,MAMapViewDelegate, AMapLocationManagerDelegate,AMapGeoFenceManagerDelegate,AMapNaviCompositeManagerDelegate{
^
/Users/zhangzhigang/.pub-cache/hosted/pub.flutter-io.cn/ai_amap-1.1.0/ios/Classes/AiAMapLocationPlatformView.swift:17:7: note: do you want to add protocol stubs?
class AiAMapLocationPlatformView:NSObject,FlutterPlatformView,MAMapViewDelegate, AMapLocationManagerDelegate,AMapGeoFenceManagerDelegate,AMapNaviCompositeManagerDelegate{
^
/Users/zhangzhigang/.pub-cache/hosted/pub.flutter-io.cn/ai_amap-1.1.0/ios/Classes/AiAMapLocationPlatformView.swift:231:46: warning: forced cast from 'String??' to 'String' only unwraps optionals; did you mean to use '!!'?
naviTitle = annotation.title as! String;
~~~~~~~~~~~~~~~~~^~~~~~~~~~
!!

> 日志如下:

日志如下:
/Users/zhangzhigang/.pub-cache/hosted/pub.flutter-io.cn/ai_amap-1.1.0/ios/Classes/AiAMapLocationPlatformView.swift:17:7: error: type 'AiAMapLocationPlatformView' does not conform to protocol 'AMapGeoFenceManagerDelegate'
class AiAMapLocationPlatformView:NSObject,FlutterPlatformView,MAMapViewDelegate, AMapLocationManagerDelegate,AMapGeoFenceManagerDelegate,AMapNaviCompositeManagerDelegate{
^
/Users/zhangzhigang/.pub-cache/hosted/pub.flutter-io.cn/ai_amap-1.1.0/ios/Classes/AiAMapLocationPlatformView.swift:17:7: note: do you want to add protocol stubs?
class AiAMapLocationPlatformView:NSObject,FlutterPlatformView,MAMapViewDelegate, AMapLocationManagerDelegate,AMapGeoFenceManagerDelegate,AMapNaviCompositeManagerDelegate{
^
/Users/zhangzhigang/.pub-cache/hosted/pub.flutter-io.cn/ai_amap-1.1.0/ios/Classes/AiAMapLocationPlatformView.swift:231:46: warning: forced cast from 'String??' to 'String' only unwraps optionals; did you mean to use '!!'?
naviTitle = annotation.title as! String;

!!

may be because of swift version difference...
what's your version about swift develop language?

Originally posted by @pdliuw in #3 (comment)

请求重构

// ignore: must_be_immutable
class AiAMapPlatformWidget extends StatefulWidget {
///
static const String UNSUPPORTED_DESCRIPTION_DEFAULT = "Unsupported platform";
String _unsupportedDescription;
///
/// constructor
AiAMapPlatformWidget({
String unsupportedDescription = UNSUPPORTED_DESCRIPTION_DEFAULT,
}) {
_unsupportedDescription =
unsupportedDescription ?? UNSUPPORTED_DESCRIPTION_DEFAULT;
}
@override
State<StatefulWidget> createState() {
return _AiAMapPlatformState(
unsupportedDescription: _unsupportedDescription);
}
}
///
/// _AiAMapPlatformState
class _AiAMapPlatformState extends State<AiAMapPlatformWidget> {
static const String _viewTypeId = "view_type_id_map_platform_view";
String _unsupportedDescription;
///
/// constructor
_AiAMapPlatformState({

  1. 支持空安全
  2. STF写法不好,不应该向state构造函数手动传参,改成final设变量,state里widget接受

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.