高德地图定位类封装
经常用到定位,索性抽出来封装成一个类,方便取用,直接上代码
package com.dydd.wsp.dreamtree.utils
import android.content.Context
import com.amap.api.location.AMapLocation
import com.amap.api.location.AMapLocationClient
import com.amap.api.location.AMapLocationClientOption
import java.text.SimpleDateFormat
import java.util.*
/**
* Created by ${吴心良} on 2018/7/5.
* E-mail:wusongpingsmile@gmail.com
* Describe:高德地图获取定位信息
*/
object LocationInfo {
fun getLocationInfo(context: Context,success:(AMapLocation)->Unit){
val mLocationClient: AMapLocationClient = AMapLocationClient(context)
val mLocationOption: AMapLocationClientOption = AMapLocationClientOption()
// 初始化定位
// 设置高德地图定位回调监听
mLocationClient.setLocationListener {aMapLocation->
if (aMapLocation != null) {
if (aMapLocation.errorCode == 0) {

本文介绍如何将高德地图的定位功能封装为一个类,便于在项目中便捷调用。通过简单示例代码展示具体使用过程。
最低0.47元/天 解锁文章
2435





