求百度地图高手帮忙,毕业设计遇到难题了
这是百度地图定位提供的例子locSDK_2.3_Demo2,在模拟器上运行error code为167,有网的,而且还模拟了GPS信号查了好久,出问题的类百度api中也没有解释
还把代码对应的名称都列出来了
BDLocation.TypeNone对应0
BDLocation.TypeGpsLocation对应61
BDLocation.TypeCriteriaException对应62
BDLocation.TypeNetWorkLocation对应161
BDLocation.TypeServerError对应167
BDLocation.TypeNetWorkException对应63
我想要61或161啊,求帮忙
public class main extends Activity {
private LocationClient mLocationClient = null;
private Button mStartBtn = null;
private TextView mTextView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mStartBtn = (Button)findViewById(R.id.button1);
mTextView = (TextView)findViewById(R.id.textview1);
mLocationClient = new LocationClient(this);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true); //打开gps
option.setCoorType("bd09ll"); //设置坐标类型为bd09ll
option.setPriority(LocationClientOption.GpsFirst); //设置网络优先
option.setProdName("locSDKDemo2"); //设置产品线名称
option.setScanSpan(5000); //定时定位,每隔5秒钟定位一次。
mLocationClient.setLocOption(option);
mLocationClient.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("\nradius : ");
sb.append(location.getRadius());
if (location.getLocType() == BDLocation.TypeGpsLocation){
sb.append("\nspeed : ");
sb.append(location.getSpeed());
sb.append("\nsatellite : ");
sb.append(location.getSatelliteNumber());
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
sb.append("\naddr : ");
sb.append(location.getAddrStr());
}
sb.append("\nsdk version : ");
sb.append(mLocationClient.getVersion());
mTextView.setText(sb.toString());
}
public void onReceivePoi(BDLocation location){
return ;
}
});
mStartBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mLocationClient == null) return ;
if (mLocationClient.isStarted()){
mLocationClient.stop();
mStartBtn.setText("开始");
} else {
mLocationClient.start();
mStartBtn.setText("关闭");
}
}
});
}
@Override
public void onDestroy(){
if (mLocationClient != null && mLocationClient.isStarted()){
mLocationClient.stop();
mLocationClient = null;
}
super.onDestroy();
}
} --------------------编程问答-------------------- 模拟器显示不了,用手机测试吧 --------------------编程问答-------------------- 我当时用百度地图API的时候是自己写的GPS管理. 获取坐标后再转换成百度坐标. --------------------编程问答-------------------- 我也使用了,出现的错误代码是162,有时出现63,求高手解释。 --------------------编程问答-------------------- 傻X 模拟器去定位 --------------------编程问答-------------------- package com.example.gpsthefirst;
import java.util.HashMap;
import java.util.Map;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.BDNotifyListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.LocationData;
import com.baidu.mapapi.map.MKMapViewListener;
import com.baidu.mapapi.map.MapController;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationOverlay;
import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.example.gpsthefirst.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.Toast;
public class Locate extends Activity {
public MapView mapView=null;
public MapController mapController=null;
public MKMapViewListener mkMapViewListener=null;
public static String latitude,longitude,direction,accuracy;
Sender sender=new Sender();
Thread thread;
public FrameLayout mapContaniner=null;
public static Double double1=0.0;
LocationClient locationClient=null;
public MyLocationListener myLocationListener =new MyLocationListener();
public MyNotifyListener myNotifyListener=null;
public Button updateButton=null;
public EditText editText=null;
MyLocationOverlay myLocationOverlay=null;
public int index=0;
LocationData locationData=null;
Handler mapHandler=new Handler(){
public void handleMessage(android.os.Message msg){
Toast.makeText(Locate.this, "msg:" +msg.what, Toast.LENGTH_LONG).show();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_locate);
mapView=(MapView) findViewById(R.id.map_view);
mapController=mapView.getController();
initMapView();
locationClient=new LocationClient(this);
locationClient.registerLocationListener(myLocationListener);
// 位置提醒 相关代码
myNotifyListener=new MyNotifyListener();
System.out.println("locate执行了!");
myNotifyListener.SetNotifyLocation(42.03249652949337,113.3129895882556, 3000, "bd09ll");
System.out.println("locate执行了!");
locationClient.registerNotify(myNotifyListener);
LocationClientOption locationClientOption=new LocationClientOption();
locationClientOption.setOpenGps(true);
locationClientOption.setCoorType("bd09ll");
locationClientOption.setScanSpan(1000);
locationClient.start();
mapView.getController().setZoom(14);
mapView.getController().enableClick(true);
mapView.displayZoomControls(true);
mkMapViewListener=new MKMapViewListener() {
@Override
public void onMapMoveFinish() {
// TODO Auto-generated method stub
}
@Override
public void onClickMapPoi(MapPoi mapPoi) {
// TODO Auto-generated method stub
String title="";
if(mapPoi!=null){
title=mapPoi.strText;
Toast.makeText(Locate.this,title,Toast.LENGTH_SHORT).show();
}
}
};
mapView.regMapViewListener(GpsApplication.getInstance().bMapManager, mkMapViewListener);
myLocationOverlay =new MyLocationOverlay(mapView);
locationData=new LocationData();
myLocationOverlay.setData(locationData);
mapView.getOverlays().add(myLocationOverlay);
myLocationOverlay.enableCompass();
mapView.refresh();
updateButton=(Button) findViewById(R.id.button_update);
updateButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
updateLocation();
}
});
// Intent service= new Intent(Locate.this,LocateService.class);
// Locate.this.startService(service);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
mapView.onPause();
super.onPause();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
// return super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
mapView.onResume();
super.onResume();
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
mapView.onSaveInstanceState(savedInstanceState);
}
public void initMapView(){
mapView.setLongClickable(true);
}
public void updateLocation(){
// if(thread!=null){
//// sender.flag=false;
//// thread.destroy();
// thread.interrupt();
// }
thread=new Thread(sender);
sender.flag=true;
thread.start();
locationClient.requestLocation();
}
public class MyLocationListener implements BDLocationListener{
@Override
public void onReceiveLocation(BDLocation location) {
// TODO Auto-generated method stub
if(location==null)
return;
locationData.latitude=location.getLatitude();
locationData.longitude=location.getLongitude();
locationData.direction=2.0f;
locationData.accuracy=location.getRadius();
locationData.direction=location.getDerect();
latitude= new Double(locationData.latitude*1e6).toString();
longitude= new Double(locationData.longitude*1e6).toString();
accuracy=new Float(locationData.accuracy).toString();
direction=new Float(locationData.direction).toString();
Log.d("loctest", String.format("...........before:lat:%f,lon:%f", location.getLatitude(),location.getLongitude()));
myLocationOverlay.setData(locationData);
mapView.refresh();
// mapController.animateTo(new GeoPoint((int)locationData.latitude* 1e6,(int)locationData.longitude* 1e6), mapHandler.obtainMessage(1)));
mapController.animateTo(new GeoPoint((int)(locationData.latitude* 1e6), (int)(locationData.longitude * 1e6)), mapHandler.obtainMessage(1));
}
@Override
public void onReceivePoi(BDLocation poilocation) {
// TODO Auto-generated method stub
if(poilocation==null)
return;
}
}
public class MyNotifyListener extends BDNotifyListener{
@Override
public void onNotify(BDLocation arg0, float arg1) {
// TODO Auto-generated method stub
super.onNotify(arg0, arg1);
}
}
}
哥的代码给你看 哥的能运行 但是哥想弄成Service
补充:移动开发 , Android