Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ios crash problem when fields of regeocode is nil. #40

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 18 additions & 116 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ android {
}

dependencies {
implementation 'com.amap.api:location:latest.integration'
implementation 'com.amap.api:location:5.5.1'
}
36 changes: 15 additions & 21 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jzoom.amaplocation">

<!-- 获取运营商信息,用于支持提供运营商信息相关的接口 -->
<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.CHANGE_CONFIGURATION"/>
<!--允许访问网络,必选权限-->
<uses-permission android:name="android.permission.INTERNET" />

<!-- 请求网络 -->
<uses-permission android:name="android.permission.INTERNET"/>
<!--允许获取粗略位置,若用GPS实现定位小蓝点功能则必选-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<!-- 不是SDK需要的权限,是示例中的后台唤醒定位需要的权限 -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!--允许获取设备和运营商信息,用于问题排查和网络定位,若无gps但仍需实现定位小蓝点功能则此权限必选-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<!--允许获取网络状态,用于网络定位,若无gps但仍需实现定位小蓝点功能则此权限必选-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!--允许获取wifi网络信息,用于网络定位,若无gps但仍需实现定位小蓝点功能则此权限必选-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<!--允许获取wifi状态改变,用于网络定位,若无gps但仍需实现定位小蓝点功能则此权限必选-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

<!-- 需要运行时注册的权限 -->
<!-- 用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- 用于访问GPS定位 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- 用于提高GPS定位速度 -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<!-- 写入扩展存储,向扩展卡写入数据,用于写入缓存定位数据 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- 读取缓存数据 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<!-- 用于读取手机当前的状态 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<!-- 更改设置 -->
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>


<application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.Intent;
import android.util.Log;

import androidx.annotation.NonNull;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
Expand All @@ -13,6 +15,7 @@
import java.util.HashMap;
import java.util.Map;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
Expand All @@ -22,36 +25,30 @@
/**
* FlutterAmapLocationPlugin
*/
public class AmapLocationPlugin implements MethodCallHandler, AMapLocationListener {

public class AmapLocationPlugin implements FlutterPlugin, MethodCallHandler, AMapLocationListener {

private Registrar registrar;
private Context context;
private MethodChannel channel;
private AMapLocationClientOption option;
private AMapLocationClient locationClient;
private boolean isLocation;
//备份至
private boolean onceLocation;

public AmapLocationPlugin(Registrar registrar, MethodChannel channel) {
this.registrar = registrar;
this.channel = channel;
}

private Activity getActivity(){
return registrar.activity();
private Context getApplicationContext(){
return context;
}

private Context getApplicationContext(){
return registrar.activity().getApplicationContext();
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
context = flutterPluginBinding.getApplicationContext();
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "amap_location");
channel.setMethodCallHandler(this);
}

/**
* Plugin registration.
*/
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "amap_location");
channel.setMethodCallHandler(new AmapLocationPlugin(registrar,channel));
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel.setMethodCallHandler(null);
}

@Override
Expand Down Expand Up @@ -222,18 +219,22 @@ private boolean startLocation(AMapLocationListener listener){
private boolean startup(Map arguments) {
synchronized (this){

if(locationClient==null){
//初始化client
locationClient = new AMapLocationClient(getApplicationContext());
//设置定位参数
AMapLocationClientOption option = new AMapLocationClientOption();
parseOptions(option,arguments);
locationClient.setLocationOption(option);
try {
if (locationClient == null) {
//初始化client
locationClient = new AMapLocationClient(getApplicationContext());
//设置定位参数
AMapLocationClientOption option = new AMapLocationClientOption();
parseOptions(option, arguments);
locationClient.setLocationOption(option);

//将option保存一下
this.option = option;
//将option保存一下
this.option = option;

return true;
return true;
}
} catch (Exception e) {
return false;
}

return false;
Expand Down
Loading