1.0.7 • Published 4 years ago

cordova-plugin-yzt-amap v1.0.7

Weekly downloads
2
License
Apache 2.0 Licens...
Repository
github
Last release
4 years ago

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-yzt-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-yzt-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-yzt-amap
$> cordova plugin add cordova-plugin-yzt-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
  • startUpdatePosition
  • readUpdatePosition
  • stopUpdatePosition
  • showMap
  • hideMap
  • traceMap

Android

npm.io

iOS

npm.io

地图插件总结

  • 做过很多项目都有使用地图的场景,原生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 文件中。

3、关于高德地图key,SHA1

1、包名(PackageName)要唯一

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

demo code repository

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


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

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