这是代码,第一个问题也是最最重要的问题:为什么定位启动textview没有显示手机位置,第二个问题:如果不用点击button开始定位,APP启动后自动定位的代码是!!!第三个问题:请求网络获取手机所在位置的权限提醒弹窗怎么取消,给她权限自动通过请求。。。谢谢大牛了!!!
参考:http://blog.csdn.net/crazy1235/article/details/43898451
http://blog.csdn.net/column/details/android-jacksen-map.html
大牛,你在哪里?自己顶!!!
加了这些代码以后textview也只是显示时间,没有显示经纬和地址,,,
就是这样子,时间也只显示2015-,经纬和地址都不显示,,,快来人呐!!!
public class StartCanteenActivity extends Activity
{
private TextView locationInfoTextView = null;
private Button startButton = null;
private LocationClient locationClient = null;
private static final int UPDATE_TIME = 5000;
private static int LOCATION_COUTNS = 0;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_canteen);
locationInfoTextView = (TextView) this.findViewById(R.id.locationTextView);
startButton = (Button) this.findViewById(R.id.location_button);
locationClient = new LocationClient(this);
//设置定位条件
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true); //是否打开GPS
option.setCoorType("bd09ll"); //设置返回值的坐标类型
option.setPriority(LocationClientOption.NetWorkFirst); //设置定位优先级
option.setScanSpan(UPDATE_TIME); //设置定时定位的时间间隔。单位毫秒
locationClient.setLocOption(option);
//注册位置监听器
locationClient.registerLocationListener(new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation location) {
if (location == null) {
return;
}
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("\nAddress : ");
sb.append(location.getAddrStr());
sb.append(String.valueOf(LOCATION_COUTNS));
locationInfoTextView.setText(sb.toString());
}
});
startButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (locationClient == null) {
return;
}
if (locationClient.isStarted()) {
startButton.setText("Start");
locationClient.stop();
}
else {
startButton.setText("Stop");
locationClient.start();
locationClient.requestLocation();
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
if (locationClient != null && locationClient.isStarted()) {
locationClient.stop();
locationClient = null;
}
}
}
大神,把触发定位的事件假放到**OnCreate()**里面要怎么做呢?_?
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_canteen);
然后嘞