百度地图移动到指定点

我是Android开发者 2012-11-22 11:09:38
求解,在oncreate的时候,设置地图中心在北京天安门,之后再调用mapController.setCenter来移动到别的地方,为什么地图没反应,但是当触摸手机的时候突然的就跳到了指定的点,如何去设置???
求高手解答!!
public class MyOverLay extends Overlay {
private GeoPoint geoPoint = null;
public MyOverLay(int x, int y) {
// TODO Auto-generated constructor stub
geoPoint = new GeoPoint(x, y);
}
//coonstruct the point on the map

//define a paint tool
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);

Point point = mapView.getProjection().toPixels(geoPoint, null);
arg0.drawText("*ME*", point.x, point.y, paint);
// mapController = mapView.getController();
// mapView.invalidate();
// mapController.setCenter(this.geoPoint);

// mapController.animateTo(this.geoPoint);
}
}

private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.d(TAG, "onReceive");
String action = intent.getAction();
Log.d(TAG, "recv action: " + action);
if(action.equals(MIRROR_SERVER)) {
//...
int x = intent.getIntExtra("POINTX", 0);
int y = intent.getIntExtra("POINTY", 0);
Log.d(TAG, "x: " + x + ", y: " + y);
mapView.getOverlays().add(new MyOverLay(x, y));
GeoPoint geoPoint = new GeoPoint(x, y);
geoPoint = new GeoPoint(x, y);
mapController.setCenter(geoPoint);
// mapController.animateTo(geoPoint);
}
}
};

当我得到broadcast发来的点信息的时候我要在该点画上一个符号,然后地图移动到这个点,但是调用了setCentre地图不动
...全文
503 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
是地图没刷新吗?那我要如何刷新呢?
q710774901 2012-11-22
  • 打赏
  • 举报
回复
地图没刷新?
  • 打赏
  • 举报
回复
百度地图上出现的问题,我要去哪找解答啊。。。
一梦清秋 2012-11-22
  • 打赏
  • 举报
回复
sercher.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub //mSearch.suggestionSearch(address.getText().toString()); mSearch.poiSearchInCity(address.getText().toString(),address.getText().toString()); if(!mydrawer.isOpened()) { mydrawer.open(); goal.setText(address.getText().toString()); cityname=address.getText().toString(); } } }); 。。。。。。。。。。。。。。。。 mBMapMan = new BMapManager(getApplication()); mBMapMan.init("D34BB8CA4F7C3947ACBCC6A186D4BC03F5916492", null); super.initMapActivity(mBMapMan); mMapView = (MapView)findViewById(R.id.mapView); mylayout=(RelativeLayout)findViewById(R.id.set); mylayout.setOnTouchListener(this); // mMapView.setOnTouchListener(this); address.setOnTouchListener(this); mMapView.setBuiltInZoomControls(true); //设置在缩放动画过程中也显示overlay,默认为不绘制 mMapView.setDrawOverlayWhenZooming(true); // 初始化搜索模块,注册事件监听 mSearch = new MKSearch(); mSearch.init(mBMapMan, new MKSearchListener(){ public void onGetPoiResult(MKPoiResult res, int type, int error) { // 错误号可参考MKEvent中的定义 if (error != 0 || res == null) { Toast.makeText(SetAddress.this, "抱歉,未找到结果", Toast.LENGTH_LONG).show(); return; } // 将地图移动到第一个POI中心点 if (res.getCurrentNumPois() > 0) { // 将poi结果显示到地图上 PoiOverlay poiOverlay = new PoiOverlay(SetAddress.this, mMapView); poiOverlay.setData(res.getAllPoi()); mMapView.getOverlays().clear(); mMapView.getOverlays().add(poiOverlay); mMapView.invalidate(); mMapView.getController().animateTo(res.getPoi(0).pt); } else if (res.getCityListNum() > 0) { mSearch.poiSearchInCity(res.getCityListInfo(0).city,address.getText().toString()); String strInfo = "在"; for (int i = 0; i < res.getCityListNum(); i++) { strInfo += res.getCityListInfo(i).city; strInfo += ","; } strInfo += "找到结果"; Toast.makeText(SetAddress.this, strInfo, Toast.LENGTH_LONG).show(); } } public void onGetDrivingRouteResult(MKDrivingRouteResult res, int error) { } public void onGetTransitRouteResult(MKTransitRouteResult res, int error) { } public void onGetWalkingRouteResult(MKWalkingRouteResult res, int error) { } public void onGetAddrResult(MKAddrInfo res, int error) { } public void onGetBusDetailResult(MKBusLineResult result, int iError) { } public void onGetSuggestionResult(MKSuggestionResult res, int arg1) { // TODO Auto-generated method stub if (arg1 != 0 || res == null) { Toast.makeText(SetAddress.this, "抱歉,未找到结果", Toast.LENGTH_LONG).show(); return; } int nSize = res.getSuggestionNum(); mStrSuggestions = new String[nSize]; for (int i = 0; i < nSize; i++) { mStrSuggestions[i] = res.getSuggestion(i).city + res.getSuggestion(i).key; } // ArrayAdapter<String> suggestionString = new ArrayAdapter<String>(.this, android.R.layout.simple_list_item_1,mStrSuggestions); // mSuggestionList.setAdapter(suggestionString); Toast.makeText(SetAddress.this, "suggestion callback", Toast.LENGTH_LONG).show(); } public void onGetRGCShareUrlResult(String arg0, int arg1) { // TODO Auto-generated method stub } }); }

80,337

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧