概述
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class OneKeyRegisterActivity extends Activity {
private TextView mTv = null;
public LocationClient mLocationClient = null;
public MyLocationListenner myListener = new MyLocationListenner();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_onekeyregister);
mLocationClient = new LocationClient( this );
mLocationClient.registerLocationListener( myListener );
mTv = (TextView)findViewById(R.id.textview);
setLocationOption();
mLocationClient.start();
}
private void setLocationOption() {
// TODO Auto-generated method stub
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true); //打开gps
option.setServiceName("com.baidu.location.service_v2.9");
option.setPoiExtraInfo(true);
option.setAddrType("all");
option.setPriority(LocationClientOption.NetWorkFirst);
option.setPriority(LocationClientOption.GpsFirst); //gps
option.setPoiNumber(10);
option.disableCache(true);
mLocationClient.setLocOption(option);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
mLocationClient.stop();
super.onDestroy();
}
public class MyLocationListenner implements BDLocationListener{
@Override
public void onReceiveLocation(BDLocation arg0) {
// TODO Auto-generated method stub
mTv.setText(arg0.getProvince() + arg0.getCity() + arg0.getStreet());
}
@Override
public void onReceivePoi(BDLocation arg0) {
// TODO Auto-generated method stub
}
}
}
最后
以上就是坚定蜡烛为你收集整理的android百度定位服务,Android利用百度定位SDK获取当前城市位置的全部内容,希望文章能够帮你解决android百度定位服务,Android利用百度定位SDK获取当前城市位置所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复