Unity接入高德SDK实现定位

一.在高德官网下载需要对应的SDK  http://lbs.amap.com/api/android-location-sdk

    通过SHA1值获取对应的key值    

   a.SHA1值得获取:  1.在cmd中定位到 .android

     2.输入keytool -list -v -keystore debug.keystore   口令是:android   

二.导入下载的高德sdk  和classes  jar文件放在lib文件下


      并点击右键添加依赖

三.编写主函数

public class MainActivity extends UnityPlayerActivity

{
    //声明mLocationClient对象
    public AMapLocationClient mLocationClient = null;
    public AMapLocationClientOption mLocationOption = null;
    private String LocationInfo;
    private String ErrorInfo="";

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
    }
    //获取定位信息
    public String[] GetInfo()
    {
        String[] a=new String[2];
        a[0]=this.LocationInfo;
        a[1]=this.ErrorInfo;
        startLocation();

        return a;
    }

    protected void onStart()
    {
        super.onStart();
    }

    private void startLocation()
    {
        this.mLocationClient = new AMapLocationClient(getApplicationContext());
        //回调监听
        this.mLocationClient.setLocationListener(this.mLocationListener);
        //初始化定位参数
        this.mLocationOption = new AMapLocationClientOption();

        this.mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        this.mLocationOption.setInterval(1000L);
        this.mLocationOption.setHttpTimeOut(10000l);
        this.mLocationOption.setNeedAddress(true);
        this.mLocationClient.setLocationOption(this.mLocationOption);
        this.mLocationClient.startLocation();
    }

    public AMapLocationListener mLocationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation location) {

            if (location != null) {
                if (location.getErrorCode() == 0) {
   
  • 2
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值