@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.bmapview); mbtnAdress = (Button) findViewById(R.id.btnAddress); mbtnAdress.setOnClickListener(this); mbtnLine = (Button) findViewById(R.id.btnLine); mbtnLine.setOnClickListener(this); bMapManager = new BMapManager(this); bMapManager.init( key, new MKGeneralListener() { @Override public void onGetPermissionState(int arg0) { // TODO Auto-generated method stub if (arg0 == 300) { Toast.makeText(MainActivity.this, "输入的key有误", 1); } } @Override public void onGetNetworkState(int arg0) {} }); bMapManager.start(); initMapActivity(bMapManager); mapView.setBuiltInZoomControls(true); // 设置中心点 mkSearch = new MKSearch(); mkSearch.init(bMapManager, new MySearchListener(this, mapView)); }
public BMapManager initBMapManager() { if (mBMapManager == null) { mBMapInstanceCount = new AtomicInteger(0); mBMapManager = new BMapManager(App.getInstance()); mBMapManager.init( Constants.BMAP_KEY, new MKGeneralListener() { @Override public void onGetNetworkState(int iError) { if (iError == MKEvent.ERROR_NETWORK_CONNECT) { App.debug("BMap ERROR_NETWORK_CONNECT"); } } @Override public void onGetPermissionState(int iError) { if (iError == MKEvent.ERROR_PERMISSION_DENIED) { App.debug("BMap ERROR_PERMISSION_DENIED"); } } }); } mBMapInstanceCount.incrementAndGet(); App.debug(TAG, "initBMapManager " + mBMapInstanceCount.get()); return mBMapManager; }
public void initEngineManager(Context context) { if (mBMapManager == null) { mBMapManager = new BMapManager(context); } if (!mBMapManager.init(strKey, new MyGeneralListener())) { Toast.makeText(this.getApplicationContext(), "BMapManager 初始化错误!", Toast.LENGTH_LONG).show(); } }
public void initBMapManager(Context context) { if (mapManager == null) mapManager = new BMapManager(context); boolean initSucceed = mapManager.init(APP_KEY, new MyGeneralListener()); if (!initSucceed) Toast.makeText( mapApplicationInstance.getApplicationContext(), "BMapManager初始化错误", Toast.LENGTH_SHORT) .show(); }
protected void initBMap(MKGeneralListener listener) { mBMapManager = new BMapManager(getApplicationContext()); mBMapManager.init(TongGouApplication.strKey, listener); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mBMapMan = new BMapManager(getApplication()); mBMapMan.init("C852FAE280E276186DE82EB547721866666283B0", null); super.initMapActivity(mBMapMan); mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); mapOverlays = mapView.getOverlays(); // first overlay drawable = getResources().getDrawable(R.drawable.marker); itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView); GeoPoint point = new GeoPoint((int) (39.90923 * 1E6), (int) (116.397428 * 1E6)); CustomOverlayItem overlayItem = new CustomOverlayItem( point, "Tomorrow Never Dies (1997)", "(M gives Bond his mission in Daimler car)", "http://ia.media-imdb.com/images/M/MV5BMTM1MTk2ODQxNV5BMl5BanBnXkFtZTcwOTY5MDg0NA@@._V1._SX40_CR0,0,40,54_.jpg"); itemizedOverlay.addOverlay(overlayItem); GeoPoint point2 = new GeoPoint((int) (39.9022 * 1E6), (int) (116.3922 * 1E6)); CustomOverlayItem overlayItem2 = new CustomOverlayItem( point2, "GoldenEye (1995)", "(Interiors Russian defence ministry council chambers in St Petersburg)", "http://ia.media-imdb.com/images/M/MV5BMzk2OTg4MTk1NF5BMl5BanBnXkFtZTcwNjExNTgzNA@@._V1._SX40_CR0,0,40,54_.jpg"); itemizedOverlay.addOverlay(overlayItem2); mapOverlays.add(itemizedOverlay); // second overlay drawable2 = getResources().getDrawable(R.drawable.marker2); itemizedOverlay2 = new CustomItemizedOverlay<CustomOverlayItem>(drawable2, mapView); GeoPoint point3 = new GeoPoint((int) (39.917723 * 1E6), (int) (116.3722 * 1E6)); CustomOverlayItem overlayItem3 = new CustomOverlayItem(point3, "Sliding Doors (1998)", "(interiors)", null); itemizedOverlay2.addOverlay(overlayItem3); GeoPoint point4 = new GeoPoint((int) (51.51738 * 1E6), (int) (-0.08186 * 1E6)); CustomOverlayItem overlayItem4 = new CustomOverlayItem( point4, "Mission: Impossible (1996)", "(Ethan & Jim cafe meeting)", "http://ia.media-imdb.com/images/M/MV5BMjAyNjk5Njk0MV5BMl5BanBnXkFtZTcwOTA4MjIyMQ@@._V1._SX40_CR0,0,40,54_.jpg"); itemizedOverlay2.addOverlay(overlayItem4); mapOverlays.add(itemizedOverlay2); final MapController mc = mapView.getController(); mc.animateTo(point2); mc.setZoom(16); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 初始化地图管理器 mMapManager = new BMapManager(getApplication()); mMapManager.init(accessKey, new MyMKGeneralListener()); // 初始化各种与地图无关的成员变量 appInit(); regeisterSensorManager(); textShow = (TextView) findViewById(R.id.textShow); textShow.setTextSize(TextShowTextSize); // 初始化mapview对象,并且设置显示缩放控件 mMapView = (MapView) findViewById(R.id.bmapsView); mMapView.setBuiltInZoomControls(true); mMapView.showScaleControl(true); mMapView.setDoubleClickZooming(false); // 定义地图控件,获取mapview的控制,并把地图范围定位在宿舍 mMapView.regMapViewListener(mMapManager, new MyMKMapViewListener()); mMapView.regMapTouchListner(new MyMKMapTouchListener()); mMapController = mMapView.getController(); // 初始化locationClient服务 clientInit(); // 此处启动,将会在第一次定位后自动关闭 mLocationClient.start(); // 使用上一次退出时的位置数据作为初始化的地点 mMapController.animateTo(new GeoPoint(appData.lastLatitude, appData.lastLongitude)); mMapController.setZoom(appData.lastZoom); // 此处进行定时器设置,定时器每隔500ms执行一次 handler = new Handler() { public void handleMessage(Message msg) { if (msg.what != MainActivity.UPDATE_TEXT) { return; } // 截图 if (isCut) { cutSpeed++; if (cutSpeed % 8 == 1) { mMapView.getCurrentMap(); } } if (!mLocationClient.isStarted() || appData.isFirst) { appData.textShowStrings[0] = "未启动导航功能"; appData.textShowStrings[1] = ""; textShow.setTextColor(Color.BLACK); appData.updateTextShow(); mMapController.setRotation(0); return; } GeoPoint curPos = new GeoPoint(appData.lastLatitude, appData.lastLongitude); double radius = roadData.getRadius(curPos); double curSpeed, safeSpeed; // 返回的应该是米每秒 safeSpeed = appData.getSafeSpeed(radius); if (safeSpeed > 120.0 / 3.6) { safeSpeed = 120.0 / 3.6; } // 该速度为 千米每小时 curSpeed = appData.lastSpeed / 3.6f; appData.textShowStrings[0] = "当前车速为:" + (int) (curSpeed * 3.6) + "km/h"; if (curSpeed <= safeSpeed) { appData.textShowStrings[1] = "安全车速为:" + (int) (safeSpeed * 3.6) + "km/h"; textShow.setTextColor(Color.BLUE); } else { appData.textShowStrings[1] = "安全车速为:" + (int) (safeSpeed * 3.6) + "km/h" + "\n您已超速!请迅速减速"; textShow.setTextColor(Color.RED); Toast.makeText(MainActivity.this, "您已超过安全车速,请迅速减速!", Toast.LENGTH_LONG).show(); } appData.updateTextShow(); } }; // 启动定时器 new Timer() .schedule( new TimerTask() { @Override public void run() { // TODO Auto-generated method stub Message msg = new Message(); msg.what = MainActivity.UPDATE_TEXT; handler.sendMessage(msg); } }, 500, 500); }