关于使用百度地图
我的需求很简单,就是定位到手机坐标后在地图上显示出当前位置,并以当前坐标在读图上画一个圈。下面是代码。 我的问题是根本监听方法根本就没有执行,获取经纬度也获取不到。 大牛帮看看是不是小弟的代码有问题,还是其他方面的原因??
public class BmapdemoActivity extends MapActivity {
/** Called when the activity is first created. */
private double longituede;
private double latitude;
//�����ؿؼ�
private MapView mapView;
private BMapManager bMapManager;
private String keyString ="EC5C7FC07ABE33E30FA21765B21076D528067D66";
private int zoomLevel;
private float size=100;
//�ڵ�ͼ�����һЩ�ؼ�
private MapController mapController;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView=(MapView) findViewById(R.id.bmapView);
longituede=Double.parseDouble(GPSInfoProvider.getInstance(BmapdemoActivity.this).getlongituede());
latitude=Double.parseDouble(GPSInfoProvider.getInstance(BmapdemoActivity.this).getlatitude());
Intent intent=new Intent(getApplicationContext(), BmapdemoActivity.class);
intent.putExtra("longituede", longituede);
intent.putExtra("latitude", latitude);
startActivity(intent);
bMapManager=new BMapManager(BmapdemoActivity.this);
bMapManager.init(keyString, new MKGeneralListener() {
public void onGetPermissionState(int arg0) {
// TODO Auto-generated method stub
if(arg0==300){
Toast.makeText(BmapdemoActivity.this, "�����key����", 1).show();
}
}
public void onGetNetworkState(int arg0) {
// TODO Auto-generated method stub
}
});
initMapActivity(bMapManager);
mapView.setBuiltInZoomControls(true);//��ʾ�����������Ź���
mapController=mapView.getController();
mapController.setZoom(12);
zoomLevel=mapView.getZoomLevel();
Drawable drawable=getResources().getDrawable(R.drawable.iconmarka);
Log.i("hhy", "1111111111111111111111111111111");
mapView.getOverlays().add(new MyOverlay());
mapView.getOverlays().add(new MyOverlayItem(drawable));
Log.i("hhy", "22222222222222222222222222222222");
}
public class MyOverlay extends Overlay{
private GeoPoint geoPoint=new GeoPoint((int)(longituede*1E6), (int)(latitude*1E6));
private Paint paint=new Paint();
@Override
public void draw(Canvas arg0, MapView arg1, boolean arg2) {
// TODO Auto-generated method stub
super.draw(arg0, arg1, arg2);
int newZoomLevel=mapView.getZoomLevel();
int level=newZoomLevel-zoomLevel;
if(level==0){
paint.setStrokeWidth(3);
paint.setStyle(Paint.Style.STROKE);
Point point=mapView.getProjection().toPixels(geoPoint, null);
arg0.drawCircle(point.x, point.y, size, paint);
zoomLevel=newZoomLevel;
}else{
paint.setStrokeWidth(3);
paint.setStyle(Paint.Style.STROKE);
Point point=mapView.getProjection().toPixels(geoPoint, null);
if(level>0){
size=size*(level+1);
}else{
size=size/Math.abs(level-1);
}
arg0.drawCircle(point.x, point.y, size, paint);
Log.i("BmapdemoActivity", mapView.getZoomLevel()+"");
Log.i("BmapdemoActivity", level+"");
zoomLevel=newZoomLevel;
}
}
}
public class MyOverlayItem extends ItemizedOverlay<OverlayItem>{
private List<OverlayItem> list=new ArrayList<OverlayItem>();
private double mlat=39.915;
private double mlon=116.404;
public MyOverlayItem(Drawable arg0) {
super(arg0);
// TODO Auto-generated constructor stub
GeoPoint geoPoint=new GeoPoint((int)(longituede*1E6), (int)(latitude*1E6));
list.add(new OverlayItem(geoPoint, "zheli", "nali"));
populate();
}
@Override
protected OverlayItem createItem(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0);
}
@Override
public int size() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public boolean onTap(int i) {
// TODO Auto-generated method stub
Toast.makeText(BmapdemoActivity.this, list.get(i).getSnippet(), 0).show();
return true;
}
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if(bMapManager!=null){
bMapManager.destroy();
bMapManager=null;
}
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if(bMapManager!=null){
bMapManager.start();
}
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
if(bMapManager!=null){
bMapManager.stop();
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
补充:移动开发 , Android