public class AMapLocationClient
extends java.lang.Object
| 构造器和说明 |
|---|
AMapLocationClient(android.content.Context context)
构造方法
constructor method |
AMapLocationClient(android.content.Context context,
android.content.Intent intent)
自定义service定位实例
Custom service location instance |
AMapLocationClient(android.os.Looper looper,
android.content.Context context)
指定looper
Specify looper |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addLogCallback(ILogCallback callback)
添加日志回调
|
void |
addSatelliteListener(IGnssSatelliteListenerDelegate listener)
设置卫星监听
|
void |
addSensorListener(ISensorListenerDelegate listener)
设置传感器监听
|
void |
disableBackgroundLocation(boolean removeNotification)
关闭后台定位功能
与
enableBackgroundLocation(int, Notification)配对使用注意:关闭后台定位功能只是代表不再提供后台定位的能力,并不是停止定位,停止定位请调用 stopLocation()。 |
void |
enableBackgroundLocation(int notificationId,
android.app.Notification notification)
开启后台定位功能
注意:
如果您设置了target>=28,需要增加android.permission.FOREGROUND_SERVICE权限,
如果您的app需要运行在Android Q版本的手机上,需要为ApsService增加android:foregroundServiceType="location"属性, 例:<service android:name="com.amap.api.location.APSService" android:foregroundServiceType="location"/> 主要是为了解决Android 8.0以上版本对后台定位的限制,开启后会显示通知栏,如果您的应用本身已经存在一个前台服务通知,则无需再开启此接口 注意:启动后台定位只是代表开启了后台定位的能力,并不代表已经开始定位,开始定位请调用 startLocation()。 |
static java.lang.String |
getDeviceId(android.content.Context context)
获取设备号
Get device ID |
AMapLocation |
getLastKnownLocation()
获取最后位置
Get last location |
void |
getReGeoLocation(AMapLocation location)
获取带有逆地理信息的定位
Get location with reverse geolocation information |
java.lang.String |
getVersion()
获取定位sdk版本信息
Get location SDK version information |
static boolean |
isHttpDnsEnabled()
返回进程级共享 HTTPDNS 是否已开启。
|
boolean |
isLocationDim() |
boolean |
isStarted()
本地定位服务是否已经启动,用于用户检查服务是否已经启动
Whether the local location service has been started, used for the user to check if the service has been started |
void |
notifyAppEnterForeBack(boolean foreground)
应用前后台变化时,通知SDK。
|
void |
notifyEventChanged(int scene,
int action,
long pNum1,
long pNum2,
java.lang.String pStr)
事件变化通知
|
void |
notifySceneChanged(int scene)
通知定位场景改变,相关定位策略会发生变化
优化定位策略,定位更准
|
void |
onDestroy()
销毁定位,释放定位资源, 当不再需要进行定位时调用此方法
该方法会释放所有定位资源,调用后再进行定位需要重新实例化AMapLocationClient
Destroy location, release location resources, call this method when location is no longer needed This method will release all location resources, and re-instantiate AMapLocationClient is required for further location after calling |
void |
removeLogCallback(ILogCallback callback)
移除日志回调
|
void |
removeSatelliteListener(IGnssSatelliteListenerDelegate listener)
移除卫星监听
|
void |
removeSensorListener(ISensorListenerDelegate listener)
移除传感器监听
|
void |
sendFeedback()
日志反馈
|
static void |
setApiKey(java.lang.String apiKey)
设置apikey 必须在AmapLocationClient实例化之前调用
Set apikey Must be called before AmapLocationClient instantiation |
static void |
setHost(java.lang.String host)
设置host 可以让sdk中所有请求都执行设置的地址,其中真实host存放在Header中
设置空表示关闭
Setting host allows all requests in the SDK to execute the set address, with the real host stored in the Header Setting empty means close |
static boolean |
setHttpDnsEnabled(boolean enabled)
设置是否启用 HTTPDNS,默认关闭。
|
void |
setLocationListener(AMapLocationListener listener)
设置定位回调监听
Set location callback listener |
void |
setLocationOption(AMapLocationClientOption option)
设置定位参数
Set location parameters |
void |
setReGeoLocationCallback(IReGeoLocationCallback callback)
设置获取逆地理信息的定位监听回调
Set the location listener callback for obtaining reverse geolocation information |
void |
startAssistantLocation(android.webkit.WebView webView)
启动H5辅助定位
只适用于Android 4.2及以后版本
该接口只用于配合Web JS API的H5辅助定位,开启后并没有开始定位,开始定位由JS API触发。
|
void |
startAssistantLocation(android.webkit.WebView webView,
AMapLocationClientOption option)
启动H5辅助定位,并配置SDK对传入WebView的WebSettings处理。
|
void |
startLocation()
开始定位
Start location |
void |
stopAssistantLocation()
停止辅助定位
如果已经调用了startAssistantLocation接口,在destroy时请调用该接口
Stop assistant location If the startAssistantLocation interface has been called, please call this interface at destroy |
void |
stopLocation()
停止定位
Stop location |
void |
unRegisterLocationListener(AMapLocationListener listener)
移除定位监听
Remove location listener |
static void |
updateCountryCode(java.lang.String countryCode)
设置国家/地区码,用于基础库统一的区域策略(如逆地理语言、服务节点选择等)。
|
static void |
updatePrivacyAgree(android.content.Context context,
boolean isAgree)
设置是否同意用户授权政策 必须在AmapLocationClient实例化之前调用
Set whether to agree to the user authorization policy Must be called before AmapLocationClient instantiation |
static void |
updatePrivacyShow(android.content.Context context,
boolean isContains,
boolean isShow)
设置包含隐私政策,并展示用户授权弹窗 必须在AmapLocationClient实例化之前调用
Set the privacy policy and display the user authorization popup Must be called before AmapLocationClient instantiation |
public AMapLocationClient(android.content.Context context)
throws java.lang.Exception
context - Android上下文
java.lang.Exceptionpublic AMapLocationClient(android.content.Context context,
android.content.Intent intent)
throws java.lang.Exception
context - intent - java.lang.Exceptionpublic AMapLocationClient(android.os.Looper looper,
android.content.Context context)
throws java.lang.Exception
looper - context - java.lang.Exceptionpublic void setLocationOption(AMapLocationClientOption option)
option - 定位参数
public void notifyEventChanged(int scene,
int action,
long pNum1,
long pNum2,
java.lang.String pStr)
scene - 场景名称 参考com.amap.location.sdk.api.define.LocationEvent.Sceneaction - 场景的具体动作 参考com.amap.location.sdk.api.define.LocationEvent.ActionpNum1 - pNum2 - pStr - public void addSensorListener(ISensorListenerDelegate listener)
listener - public void removeSensorListener(ISensorListenerDelegate listener)
listener - public void addSatelliteListener(IGnssSatelliteListenerDelegate listener)
listener - public void removeSatelliteListener(IGnssSatelliteListenerDelegate listener)
listener - public void addLogCallback(ILogCallback callback)
callback - 日志回调public void removeLogCallback(ILogCallback callback)
callback - 日志回调public void setLocationListener(AMapLocationListener listener)
listener - 定位完成后的回调接口
public void startLocation()
public void stopLocation()
public AMapLocation getLastKnownLocation()
public void notifyAppEnterForeBack(boolean foreground)
foreground - public void notifySceneChanged(int scene)
scene - public void sendFeedback()
public boolean isLocationDim()
public void startAssistantLocation(android.webkit.WebView webView)
webView - 自定义的webView
public void startAssistantLocation(android.webkit.WebView webView,
AMapLocationClientOption option)
startAssistantLocation(WebView)一致。
startAssistantLocation(WebView).webView - 自定义的webView
option - H5辅助定位配置
public void stopAssistantLocation()
如果已经调用了startAssistantLocation接口,在destroy时请调用该接口
If the startAssistantLocation interface has been called, please call this interface at destroy
public java.lang.String getVersion()
public static void updatePrivacyShow(android.content.Context context,
boolean isContains,
boolean isShow)
context - isContains: - 是隐私权政策是否包含高德开平隐私权政策 true是包含
isShow: - 隐私权政策是否弹窗展示告知用户 true是展示
public static void updateCountryCode(java.lang.String countryCode)
countryCode - 国家/地区码,如 "ZH"(中国大陆)、"SG"(新加坡/海外)
public static boolean setHttpDnsEnabled(boolean enabled)
enabled - true 启用,false 关闭
public static boolean isHttpDnsEnabled()
public static void updatePrivacyAgree(android.content.Context context,
boolean isAgree)
context - isAgree:隐私权政策是否取得用户同意 - true是用户同意
public static void setApiKey(java.lang.String apiKey)
apiKey - 要设置的apikey
public boolean isStarted()
public void unRegisterLocationListener(AMapLocationListener listener)
listener - 要移除的定位监听
public void setReGeoLocationCallback(IReGeoLocationCallback callback)
callback - 带有逆地理信息的定位监听
public void getReGeoLocation(AMapLocation location)
location - 要获取逆地理信息的位置
public void onDestroy()
该方法会释放所有定位资源,调用后再进行定位需要重新实例化AMapLocationClient
This method will release all location resources, and re-instantiate AMapLocationClient is required for further location after calling
public void enableBackgroundLocation(int notificationId,
android.app.Notification notification)
主要是为了解决Android 8.0以上版本对后台定位的限制,开启后会显示通知栏,如果您的应用本身已经存在一个前台服务通知,则无需再开启此接口
注意:启动后台定位只是代表开启了后台定位的能力,并不代表已经开始定位,开始定位请调用startLocation()。
建议:在整个APP中如果存在多个AMapLocationClient,只需要其中一个开启就可以了,无需重复启动,重复启动也只会显示一个通知栏。
Mainly to solve the background location restrictions on Android 8.0 and above, enabling this will display a notification bar. If your app already has a foreground service notification, you do not need to enable this interface.
Note: Enabling background location only means the capability is activated, not that location has started. To start location, call startLocation().
Recommendation: If there are multiple AMapLocationClient instances in the entire APP, only one needs to be enabled. There is no need to enable repeatedly, as repeated enabling will only display one notification bar.
notificationId - 通知栏ID,建议这个app唯一; 不能为0
notification - 自定义通知栏,使用者可以根据自己业务需求自定义Notification,将创建好的Notification对象传入;不能为null
public void disableBackgroundLocation(boolean removeNotification)
与enableBackgroundLocation(int, Notification)配对使用
注意:关闭后台定位功能只是代表不再提供后台定位的能力,并不是停止定位,停止定位请调用stopLocation()。
如果在整个APP中如果有调用enableBackgroundLocation(int, Notification),必须调用该方法。
如果同时有多个AMapLocationClient调用了enableBackgroundLocation(int, Notification),只有全部的client
都调用了disableBackgroundLocation(true),通知栏才会消失。
注意:如果您设置了target>=28,需要增加android.permission.FOREGROUND_SERVICE权限
Disable background location function
Used in pair with enableBackgroundLocation(int, Notification)
Note: Disabling background location only means the capability is no longer provided, not that location is stopped. To stop location, call stopLocation().
If enableBackgroundLocation(int, Notification) is called anywhere in the entire APP, this method must be called.
If multiple AMapLocationClient instances have called enableBackgroundLocation(int, Notification), the notification bar will only disappear when all clients
have called disableBackgroundLocation(true).
Note: If you set target>=28, you need to add android.permission.FOREGROUND_SERVICE permission
removeNotification - 是否移除通知栏, true:移除通知栏,false:不移除通知栏,可以手动移除
public static java.lang.String getDeviceId(android.content.Context context)
context - public static void setHost(java.lang.String host)