android 调用百度sdk后运行不了,android studio调用百度SDK进行定位,老返回错误码62,怎么回事...

主方法

package demo.baidudemo;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

import com.baidu.location.LocationClient;

import com.baidu.location.LocationClientOption;

public class MapsActivity extends Activity {

public LocationClient mLocationClient = null;

private LocationClientOption.LocationMode tempMode = LocationClientOption.LocationMode.Hight_Accuracy;

private String tempcoor="gcj02";

private TextView textView1;

private Button button;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.this_one);

mLocationClient = ((LocationApplication)getApplication()).mLocationClient;

textView1= (TextView) findViewById(R.id.textView1);

button= (Button) findViewById(R.id.startLocation);

((LocationApplication)getApplication()).mLocationResult = textView1;

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

InitLocation();

mLocationClient.start();

}

});

}

private void InitLocation(){

LocationClientOption option = new LocationClientOption();

option.setOpenGps(true);

option.setLocationMode(tempMode);//设置定位模式

option.setCoorType(tempcoor);//返回的定位结果是百度经纬度,默认值gcj02

int span=10000;

option.setScanSpan(span);

//设置发起定位请求的间隔时间为5000ms

option.setIsNeedAddress(true);

mLocationClient.setLocOption(option);

}

@Override

protected void onStop() {

mLocationClient.stop();

super.onStop();

}

}

Localapplition文件:

package demo.baidudemo;

import com.baidu.location.BDLocation;

import com.baidu.location.BDLocationListener;

import com.baidu.location.LocationClient;

import android.app.Application;

import android.app.Service;

import android.os.Vibrator;

import android.util.Log;

import android.widget.TextView;

/**

* 主Application

*/

public class LocationApplication extends Application {

public LocationClient mLocationClient;

public MyLocationListener mMyLocationListener;

public TextView mLocationResult,logMsg;

public Vibrator mVibrator;

@Override

public void onCreate() {

super.onCreate();

mLocationClient = new LocationClient(this.getApplicationContext());

mMyLocationListener = new MyLocationListener();

mLocationClient.registerLocationListener(mMyLocationListener);

mVibrator =(Vibrator)getApplicationContext().

getSystemService(Service.VIBRATOR_SERVICE);

}

/**

* 实现实位回调监听

*/

public class MyLocationListener implements BDLocationListener {

@Override

public void onReceiveLocation(BDLocation location) {

//Receive Location

StringBuffer sb = new StringBuffer(256);

sb.append("time : ");

sb.append(location.getTime());

sb.append("\nerror code : ");

sb.append(location.getLocType());

sb.append("\nlatitude : ");

sb.append(location.getLatitude());

sb.append("\nlontitude : ");

sb.append(location.getLongitude());

sb.append("\nradius : ");

sb.append(location.getRadius());

if (location.getLocType() == BDLocation.TypeGpsLocation){

sb.append("\nspeed : ");

sb.append(location.getSpeed());

sb.append("\nsatellite : ");

sb.append(location.getSatelliteNumber());

sb.append("\ndirection : ");

sb.append("\naddr : ");

sb.append(location.getAddrStr());

sb.append(location.getDirection());

} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){

sb.append("\naddr : ");

sb.append(location.getAddrStr());

//运营商信息

sb.append("\noperationers : ");

sb.append(location.getOperators());

}

logMsg(sb.toString());

Log.i("BaiduLocationApiDem", sb.toString());

}

}

/**

* 显示请求字符串

* @param str

*/

public void logMsg(String str) {

try {

if (mLocationResult != null)

mLocationResult.setText(str);

} catch (Exception e) {

e.printStackTrace();

}

}

}

谁能帮我看看~感激不尽

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值