All Projects → Silverbase-FE → cordova-plugin-amap

Silverbase-FE / cordova-plugin-amap

Licence: Apache-2.0 license
Amap Maps plugin for Cordova

Programming Languages

objective c
16641 projects - #2 most used programming language
java
68154 projects - #9 most used programming language
c
50402 projects - #5 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to cordova-plugin-amap

cordova-plugin-flurryanalytics
Adds support for all that Flurry Analytics flavored goodness to your Cordova based apps
Stars: ✭ 23 (-54.9%)
Mutual labels:  cordova, ionic, phonegap
Onesignal Cordova Sdk
OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com
Stars: ✭ 214 (+319.61%)
Mutual labels:  cordova, ionic, phonegap
Cordova Ionic Phonegap Branch Deep Linking Attribution
The Branch Cordova Ionic Phonegap SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
Stars: ✭ 228 (+347.06%)
Mutual labels:  cordova, ionic, phonegap
cordova-plugin-exoplayer
Media player plugin for Cordova that uses Google's ExoPlayer
Stars: ✭ 48 (-5.88%)
Mutual labels:  cordova, ionic, phonegap
Awesome Cordova
📱 A curated list of amazingly awesome Cordova libraries, resources and shiny things.
Stars: ✭ 269 (+427.45%)
Mutual labels:  cordova, ionic, phonegap
ionic4-angular6-crud-example
Building CRUD Mobile App using Ionic 4, Angular 6 and Cordova
Stars: ✭ 50 (-1.96%)
Mutual labels:  cordova, ionic, phonegap
ionic3-angular4-sample-app
Sample app of Ionic 3 and Angular 4
Stars: ✭ 35 (-31.37%)
Mutual labels:  cordova, ionic, phonegap
ionic-multi-camera
Take multiple photos one after another
Stars: ✭ 12 (-76.47%)
Mutual labels:  cordova, ionic, phonegap
Cordova Admob Pro
🔥 Cordova Plugin for Google AdMob, DFP, ADX. Easy monetization using mobile Ad, with single line of JavaScript. Compatible with Cordova CLI, Inoic, PhoneGap Build, etc.
Stars: ✭ 690 (+1252.94%)
Mutual labels:  cordova, ionic, phonegap
Intercom Cordova
Cordova/PhoneGap plugin for Intercom
Stars: ✭ 88 (+72.55%)
Mutual labels:  cordova, ionic, phonegap
Cordova Plugin Fingerprint Aio
👆 📱 Cordova Plugin for fingerprint sensors (and FaceID) with Android and iOS support
Stars: ✭ 236 (+362.75%)
Mutual labels:  cordova, ionic
Ews Javascript Api
EWS API for TypeScript/JavaScript - ported from OfficeDev/ews-managed-api - node, cordova, meteor, Ionic, Electron, Outlook Add-Ins
Stars: ✭ 241 (+372.55%)
Mutual labels:  cordova, ionic
ionic4-angular7-example
Ionic 4, Angular 7 and Cordova Tutorial: Build CRUD Mobile Apps
Stars: ✭ 57 (+11.76%)
Mutual labels:  cordova, ionic
haoshiyou-client
Source code for haoshiyou clients (Hybrid HTML5 App)
Stars: ✭ 14 (-72.55%)
Mutual labels:  cordova, ionic
cordova-plugin-1password
Plugin for adding 1Password App Extension into Cordova/PhoneGap Apps
Stars: ✭ 12 (-76.47%)
Mutual labels:  cordova, phonegap
cordova-plugin-android-window-background
Simple Cordova plugin to set Android window background on start-up 🎨 🍭
Stars: ✭ 15 (-70.59%)
Mutual labels:  cordova, ionic
Wooionic3
An eCommerce App for WooCommerce stores using Ionic 3.
Stars: ✭ 208 (+307.84%)
Mutual labels:  cordova, ionic
capacitor-rate-app
Let users rate your app using native review app dialog for both Android and iOS.
Stars: ✭ 88 (+72.55%)
Mutual labels:  cordova, ionic
framework7-template-split-view
Deprecated! Framework7 split view starter app template
Stars: ✭ 19 (-62.75%)
Mutual labels:  cordova, phonegap
docker-cordova
🗿 Docker image for Cordova (with Node.js & Android)
Stars: ✭ 72 (+41.18%)
Mutual labels:  cordova, phonegap

cordova Amap plugin for iOS and Android

This plugin is a thin wrapper for Amap Maps Android API and Amap Maps SDK for iOS. Both PhoneGap and Apache Cordova are supported.


Quick install

npm (current stable 2.0.1)

$> cordova plugin add cordova-plugin-amap --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE"

Github (current master, potentially unstable)

$> cordova plugin add https://github.com/Silverbase-FE/cordova-plugin-amap --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE"

If you re-install the plugin, please always remove the plugin first, then remove the SDK

$> cordova plugin rm cordova-plugin-amap
$> cordova plugin add cordova-plugin-amap --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE"

The SDK-Plugin won't be uninstalled automatically and you will stuck on an old version.

API Reference

  • getCurrentPosition
// Get current address for once
// 获取当前地址

if (typeof AMapPlugin != 'undefined') {
    AMapPlugin.getCurrentPosition(function (data) {
      // success
      console.log(data);
    }, function (err) {
      // fail
      console.log(err);
    })
}
  • startUpdatePosition
  • readUpdatePosition
// Turn on continuous positioning
// 开启持续定位

// Read continuous positioning data
// 读取持续定位数据
if (typeof AMapPlugin != 'undefined') {
  console.log(AMapPlugin.startUpdatePosition);
  AMapPlugin.startUpdatePosition(function (data) {
    if (data == 200) {
    	AMapPlugin.readUpdatePosition(function(data) {
    		// success
	     console.log(data);
	   }, function(err) {
	   		// fail
	     alert("err" + JSON.stringify(err));
	   });
    } else {
    	// fail
    	console.log(data);
    }
  }, function(err) {
    alert("err" + JSON.stringify(err));
  });  
}
  • stopUpdatePosition
// Stop update position
// 停止定位
  • showMap
// Show Map
// 展示地图
  • hideMap
// Hide Map
// 隐藏地图
  • traceMap
// Trace Map
// 轨迹地图

Android

iOS

地图插件总结

  • 做过很多项目都有使用地图的场景,原生app,混合app,H5页面,有基于gps信号定位的,基于ip定位的,基于基站定位的。比如:

cordova-plugin-geolocation

Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs. There is no guarantee that the API returns the device's actual location.

在实际的使用过程中,误差在1km左右,并没有描述的这么精确。而且在一些gps有问题的手机上,这个是不会有返回的,比如小米4。

H5定位,根据ip,这个误差就不提了。

目前采用的cordova调用高德地图sdk的方式,采用GPS定位,基站定位,混合定位三种定位模式,精度还算比较理想,误差在10m左右。获取的经纬度信息后可选择调用,经纬度地理信息转换接口,就可以清楚的看到当前的位置信息。这是一种较好的高精度定位解决方案。

  • 遇到的坑

1、Cordova Android 7.0.0后生成的Platform Android目录结构有变更。官方说明文档

With this release, we have changed the default project structure for Android projects. People who currently use the CLI and treat everything in the platforms directory as a build artifact should not notice a difference.

2、Android 6.0及以上版本 动态权限问题

Android 6.0及以上版本调用原生功能,需要加入动态权限。示例代码如下图所示,加在生成的 MainActivity.java 文件中。

public class GpsActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback {

    private static final int PERMISSON_REQUESTCODE = 0;
    private static final int SETTING_REQUESTCODE = 1;
    /**
     * 判断是否需要检测,防止不停的弹框
     */
    private boolean isNeedCheck = true;
    /**
     * 需要进行检测的权限数组
     */
    protected String[] needPermissions = {
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
    };


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gps);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (isNeedCheck) {
            checkPermissions(needPermissions);
        }
    }


    /**
     * 检查权限
     *
     * @param permissions
     * @since 2.5.0
     */
    private void checkPermissions(String... permissions) {
        //当前系统大于等于6.0就去动态请求权限
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            List needRequestPermissonList = findDeniedPermissions(permissions);
            if (null != needRequestPermissonList
                    && needRequestPermissonList.size() > 0) {
                ActivityCompat.requestPermissions(this,
                        needRequestPermissonList.toArray(
                                new String[needRequestPermissonList.size()]),
                        PERMISSON_REQUESTCODE);
            }
        }
    }


    /**
     * 获取权限集中需要申请权限的列表
     *
     * @param permissions
     * @return
     * @since 2.5.0
     */
    private List findDeniedPermissions(String[] permissions) {
        List needRequestPermissonList = new ArrayList();
        for (String perm : permissions) {
            if (ContextCompat.checkSelfPermission(this,
                    perm) != PackageManager.PERMISSION_GRANTED
                    || ActivityCompat.shouldShowRequestPermissionRationale(
                    this, perm)) {
                needRequestPermissonList.add(perm);
            }
        }
        return needRequestPermissonList;
    }


    /**
     * 检测是否所有的权限都已经授权
     *
     * @param grantResults
     * @return
     * @since 2.5.0
     */
    private boolean verifyPermissions(int[] grantResults) {
        for (int result : grantResults) {
            if (result != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
    }


    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String[] permissions, int[] paramArrayOfInt) {
        if (requestCode == PERMISSON_REQUESTCODE) {
            if (!verifyPermissions(paramArrayOfInt)) {
                showMissingPermissionDialog();
                isNeedCheck = false;
            }
        }
    }


    /**
     * 显示提示信息
     *
     * @since 2.5.0
     */
    private void showMissingPermissionDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("温馨提示");
        builder.setMessage("现在去设置界面配置权限吗?");

        // 拒绝, 退出应用
        builder.setNegativeButton("拒绝",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                });

        builder.setPositiveButton("好的",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startAppSettings();
                    }
                });

        builder.setCancelable(false);

        builder.show();
    }


    /**
     * 启动应用的设置
     *
     * @since 2.5.0
     */
    private void startAppSettings() {
        Intent intent = new Intent(
                Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.parse("package:" + getPackageName()));
        startActivityForResult(intent, SETTING_REQUESTCODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SETTING_REQUESTCODE) {
            checkPermissions(needPermissions);
        }
    }

}

3、关于高德地图key,SHA1

1、包名(PackageName)要唯一

2、每次打包需要是发布版安全码SHA1的签名包,不然会报错。如何获取发布版安全码SHA1

demo code repository

https://github.com/Silverbase-FE/testApp-plugin-amap 点击前往


开发调试插件,也是花费了大量的业余时间,如果对您有帮助,点个star吧!

由于能力有限,如有纰漏,欢迎多多交流!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].