@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_overlay); mMapView = (MapView) findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(14.0f); mBaiduMap.setMapStatus(msu); initOverlay(); mBaiduMap.setOnMarkerClickListener( new OnMarkerClickListener() { public boolean onMarkerClick(final Marker marker) { Button button = new Button(getApplicationContext()); button.setBackgroundResource(R.drawable.popup); OnInfoWindowClickListener listener = null; if (marker == mMarkerList.get(0) || marker == mMarkerList.get(3)) { button.setText("更改位置"); listener = new OnInfoWindowClickListener() { public void onInfoWindowClick() { LatLng ll = marker.getPosition(); LatLng llNew = new LatLng(ll.latitude + 0.005, ll.longitude + 0.005); marker.setPosition(llNew); mBaiduMap.hideInfoWindow(); } }; LatLng ll = marker.getPosition(); mInfoWindow = new InfoWindow(BitmapDescriptorFactory.fromView(button), ll, -47, listener); mBaiduMap.showInfoWindow(mInfoWindow); } else if (marker == mMarkerList.get(1)) { button.setText("更改图标"); button.setOnClickListener( new OnClickListener() { public void onClick(View v) { marker.setIcon(mBitmapList.get(4)); mBaiduMap.hideInfoWindow(); } }); LatLng ll = marker.getPosition(); mInfoWindow = new InfoWindow(button, ll, -47); mBaiduMap.showInfoWindow(mInfoWindow); } else if (marker == mMarkerList.get(2)) { button.setText("删除"); button.setOnClickListener( new OnClickListener() { public void onClick(View v) { marker.remove(); mBaiduMap.hideInfoWindow(); } }); LatLng ll = marker.getPosition(); mInfoWindow = new InfoWindow(button, ll, -47); mBaiduMap.showInfoWindow(mInfoWindow); } return true; } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.activity_main); this.context = this; mapView = (MapView) findViewById(R.id.bmapView); // 设置初始的地图比例 500米 mBaiduMap = mapView.getMap(); MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f); mBaiduMap.setMapStatus(msu); // 初始化定位 initLocation(); }
/** 放大级别 3 - 19 */ @SuppressLint("NewApi") private void perfomZoom(boolean isZoomIn) { try { MapStatusUpdate u; zoomLevel = mBaiduMap.getMapStatus().zoom; if (isZoomIn) { zoomOutButton.setImageResource(R.drawable.main_icon_zoomout); if (zoomLevel + 0.5 < mBaiduMap.getMaxZoomLevel() * 0.9) { zoomLevel += 0.5; u = MapStatusUpdateFactory.zoomTo(zoomLevel); } else { zoomLevel = (float) (mBaiduMap.getMaxZoomLevel() * 0.9); u = MapStatusUpdateFactory.zoomTo(zoomLevel); zoomInButton.setImageResource(R.drawable.main_icon_zoomin_dis); } zoomInButton.setBackground( getResources().getDrawable(R.drawable.main_widget_bottombutton_selector)); } else { zoomInButton.setImageResource(R.drawable.main_icon_zoomin); if (zoomLevel - 0.5 > mBaiduMap.getMinZoomLevel() + 5) { zoomLevel -= 0.5; u = MapStatusUpdateFactory.zoomTo(zoomLevel); } else { zoomLevel = mBaiduMap.getMinZoomLevel() + 5; u = MapStatusUpdateFactory.zoomTo(zoomLevel); zoomOutButton.setImageResource(R.drawable.main_icon_zoomout_dis); } zoomOutButton.setBackground( getResources().getDrawable(R.drawable.main_widget_bottombutton_selector)); } mBaiduMap.animateMapStatus(u); } catch (NumberFormatException e) { e.printStackTrace(); } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "[ACTIVITY] onCreate"); super.onCreate(savedInstanceState); instance = this; // 在使用SDK各组件之前初始化context信息,传入ApplicationContext // 注意该方法要再setContentView方法之前实现 SDKInitializer.initialize(getApplicationContext()); mStepValue = 0; mPaceValue = 0; setContentView(R.layout.layoutmain); mUtils = Utils.getInstance(); mMapView = (MapView) findViewById(R.id.bmapView); // sendButton = (Button) findViewById(R.id.btn_location_send); Intent intent = getIntent(); double latitude = intent.getDoubleExtra("latitude", 0); mCurrentMode = LocationMode.NORMAL; mBaiduMap = mMapView.getMap(); MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f); mBaiduMap.setMapStatus(msu); initMapView(); if (latitude == 0) { mMapView = new MapView(this, new BaiduMapOptions()); mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, null)); showMapWithLocationClient(); } else { double longtitude = intent.getDoubleExtra("longitude", 0); String address = intent.getStringExtra("address"); LatLng p = new LatLng(latitude, longtitude); mMapView = new MapView( this, new BaiduMapOptions().mapStatus(new MapStatus.Builder().target(p).build())); showMap(latitude, longtitude, address); } // 注册 SDK 广播监听者 IntentFilter iFilter = new IntentFilter(); iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR); iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR); mBaiduReceiver = new BaiduSDKReceiver(); registerReceiver(mBaiduReceiver, iFilter); }
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view = inflater.inflate(R.layout.yiyaogongsi, null); mContext = getActivity(); mMapView = (MapView) view.findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(14.0f); mBaiduMap.setMapStatus(msu); LatLng ll = new LatLng( Double.parseDouble(AmbServicesFragment.lat), Double.parseDouble("" + AmbServicesFragment.Long)); MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll); if (u != null && mBaiduMap != null) { mBaiduMap.animateMapStatus(u); } getDate(); return view; }
private void initViews() { orderInfo = getIntent().getParcelableExtra(AutoCon.ORDER_INFO); mainTech = (TextView) findViewById(R.id.main_tech); mMapView = (MapView) findViewById(R.id.bdmapView); distance = (TextView) findViewById(R.id.distance); indentImage = (ImageView) findViewById(R.id.indent_image); indentText = (TextView) findViewById(R.id.indent_text); workTime = (TextView) findViewById(R.id.work_time); orderType = (TextView) findViewById(R.id.order_type); orderOwner = (TextView) findViewById(R.id.create_order_people); shopsLocation = (TextView) findViewById(R.id.shops_location); shopsAlias = (TextView) findViewById(R.id.shops_name); workNotes = (TextView) findViewById(R.id.work_notes); baiduMap = mMapView.getMap(); // 管理具体的某一个MapView对象,缩放,旋转,平移 MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.zoomTo(BaiduMapUtil.defaultLevel); // 默认级别12 baiduMap.setMapStatus(mapStatusUpdate); // 设置缩放级别 BaiduMapUtil.hiddenBaiduLogo(mMapView); // 隐藏百度广告图标 mMapView.showZoomControls(false); mMapView.showScaleControl(true); // 默认是true,显示标尺 BaiduMapUtil.initData(); setListener(); if (orderInfo != null) { orderId = orderInfo.getId(); mainTech.setText(orderInfo.getMainTech().getName()); setData(orderInfo); } else { T.show(this, R.string.loading_data_failure); return; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.activity_main); initView(); map = mapView.getMap(); setSupportActionBar(toolbar); locationListener = new MyLocationListener(mapView, this); // 地图初始化 map.setMyLocationEnabled(true); locationClient = new LocationClient(this); locationClient.registerLocationListener(locationListener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); option.setScanSpan(5000); option.setCoorType("bd09ll"); option.setAddrType("all"); locationClient.setLocOption(option); locationClient.start(); map.setMapStatus(MapStatusUpdateFactory.zoomTo(16)); // 设置初始缩放等级 initOrientationListener(); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { centerToCurrentPlace(); } }); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawerLayout.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); // 长按添加一个Marker map.setOnMapLongClickListener( new BaiduMap.OnMapLongClickListener() { @Override public void onMapLongClick(LatLng latLng) { OverlayOptions oo = new MarkerOptions().icon(bd).position(latLng); map.addOverlay(oo); } }); map.setOnMapClickListener( new BaiduMap.OnMapClickListener() { @Override public void onMapClick(LatLng latLng) { map.hideInfoWindow(); } @Override public boolean onMapPoiClick(MapPoi mapPoi) { return false; } }); map.setOnMarkerClickListener( new BaiduMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(final Marker marker) { Toast.makeText( getApplicationContext(), "点击了" + marker.getPosition().toString(), Toast.LENGTH_SHORT) .show(); Button button = new Button(getApplicationContext()); button.setBackgroundResource(R.drawable.popup); button.setText("活动点"); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { marker.remove(); map.hideInfoWindow(); } }); InfoWindow info = new InfoWindow(button, marker.getPosition(), -100); map.showInfoWindow(info); return true; } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SDKInitializer.initialize(getApplicationContext()); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); tanchu = (Button) findViewById(R.id.tanchu); mapview = (MapView) findViewById(R.id.bmapView); this.context = this; MapStatusUpdate chengdu = MapStatusUpdateFactory.zoomTo(15.0f); mapdu = mapview.getMap(); mapdu.setMapStatus(chengdu); tanchu.setOnClickListener(this); initLocation(); initMapWu(); mapdu.setOnMarkerClickListener( new OnMarkerClickListener() { public boolean onMarkerClick(Marker marker) { // TODO Auto-generated method stub Bundle bundle = marker.getExtraInfo(); // 获得Marker中的信息 // info dedao = (info) bundle.getSerializable("info"); // Toast.makeText(context, dedao.getName(), 0).show(); Intent intent = new Intent(); intent.setClass(context, detail_content.class); intent.putExtras(bundle); // 传递bundle的值 /* 点击添加物,显示添加物的地理位置 InfoWindow infowindow ; TextView text = new TextView(context); text.setBackgroundResource(getResources().getDrawable(R.drawable.)); text.setPadding(30, 20, 30, 50); info dedao = (info) bundle.getSerializable("info"); text.setText(dedao.getName()); //final常量不能被更改 final LatLng latlng = marker.getPosition(); //得到此标记的经纬度 Point p = mapdu.getProjection().toScreenLocation(latlng) ; //将经纬度转化成屏幕上的点 p.y -= 47; LatLng ii = mapdu.getProjection().fromScreenLocation(p); //把点转化成经纬度 infowindow = new InfoWindow(text, ii, (Integer) null);*/ startActivity(intent); return true; } }); /* mapdu.setOnMapClickListener(new OnMapClickListener() { public boolean onMapPoiClick(MapPoi arg0) { // TODO Auto-generated method stub return false; } public void onMapClick(LatLng arg0) { // TODO Auto-generated method stub MarkerLinear.setVisibility(View.INVISIBLE); //消失 } });*/ }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.activity_main); this.context = this; mapView = (MapView) findViewById(R.id.bmapView); // 设置初始的地图比例 500米 mBaiduMap = mapView.getMap(); MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f); mBaiduMap.setMapStatus(msu); // 初始化定位 initLocation(); initMarker(); mBaiduMap.setOnMarkerClickListener( new OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { Bundle extraInfo = marker.getExtraInfo(); Info info = (Info) extraInfo.getSerializable("info"); ImageView iv = (ImageView) mMarkerLy.findViewById(R.id.id_info_img); TextView distance = (TextView) mMarkerLy.findViewById(R.id.id_info_distance); TextView name = (TextView) mMarkerLy.findViewById(R.id.id_info_name); TextView zan = (TextView) mMarkerLy.findViewById(R.id.id_info_zan); iv.setImageResource(info.getImgId()); distance.setText(info.getDistance()); name.setText(info.getName()); zan.setText(info.getZan() + ""); // 初始化一个infowindow InfoWindow infoWindow; TextView tv = new TextView(context); tv.setBackgroundResource(R.drawable.location_tips); tv.setPadding(30, 20, 30, 50); tv.setText(info.getName()); tv.setTextColor(Color.parseColor("#ffffff")); final LatLng latLng = marker.getPosition(); Point p = mBaiduMap.getProjection().toScreenLocation(latLng); p.y -= 47; LatLng ll = mBaiduMap.getProjection().fromScreenLocation(p); // 地图SDK发生更改,第一个参数要使用bitmap BitmapDescriptor tvBD = BitmapDescriptorFactory.fromView(tv); infoWindow = new InfoWindow( tvBD, ll, 0, new InfoWindow.OnInfoWindowClickListener() { @Override public void onInfoWindowClick() { // TODO Auto-generated method stub mBaiduMap.hideInfoWindow(); } }); mBaiduMap.showInfoWindow(infoWindow); mMarkerLy.setVisibility(View.VISIBLE); return true; } }); mBaiduMap.setOnMapClickListener( new OnMapClickListener() { @Override public boolean onMapPoiClick(MapPoi arg0) { // TODO Auto-generated method stub return false; } @Override public void onMapClick(LatLng arg0) { // TODO Auto-generated method stub mMarkerLy.setVisibility(View.GONE); mBaiduMap.hideInfoWindow(); } }); }
private void initialLayout() { mLatitude = Double.parseDouble(preference.getString("latitude", "0.00")); mLongitude = Double.parseDouble(preference.getString("longitude", "0.00")); mapView = (MapView) findViewById(R.id.mapView); // 去掉百度Logo int count = mapView.getChildCount(); for (int i = 0; i < count; i++) { View child = mapView.getChildAt(i); if (child instanceof ImageView) { child.setVisibility(View.INVISIBLE); } } baiduMap = mapView.getMap(); // 初始化地图位置 locLatLng = new LatLng(mLatitude, mLongitude); MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(locLatLng); baiduMap.animateMapStatus(u); // 设置地图放大级别 0-19 MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(17); baiduMap.animateMapStatus(msu); // 开启定位图层 baiduMap.setMyLocationEnabled(true); // 自定义Maker BitmapDescriptor mCurrentMarker = BitmapDescriptorFactory.fromResource(R.drawable.icon_arrow_up); baiduMap.setOnMapClickListener( new OnMapClickListener() { @Override public boolean onMapPoiClick(MapPoi mapPoi) { clickLatLng = mapPoi.getPosition(); addMakerToMap(clickLatLng); isClick = true; Toast.makeText( getApplicationContext(), "您选中了:" + mapPoi.getName().replace("\\", ""), Toast.LENGTH_SHORT) .show(); return false; } @Override public void onMapClick(LatLng latLng) { clickLatLng = latLng; addMakerToMap(clickLatLng); isClick = true; } }); layoutConfirm = (RelativeLayout) findViewById(R.id.layoutConfirm); layoutConfirm.setOnClickListener(new MyOnClickListener()); btnConfirm = (Button) findViewById(R.id.btnConfirm); btnConfirm.setOnClickListener(new MyOnClickListener()); layoutBack = (RelativeLayout) findViewById(R.id.layoutBack); layoutBack.setOnClickListener(new MyOnClickListener()); btnBack = (Button) findViewById(R.id.btnBack); btnBack.setOnClickListener(new MyOnClickListener()); textHint = (TextView) findViewById(R.id.textHint); imageHandClick = (ImageView) findViewById(R.id.imageHandClick); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.activity_main); b = (Button) findViewById(R.id.shit); c = (Button) findViewById(R.id.shit2); n = (NumberPicker) findViewById(R.id.num); n.setMaxValue(5); n.setMinValue(0); //// b.setVisibility(View.INVISIBLE); map = file(); map2 = file2(); mMapView = (MapView) findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); MapStatusUpdate u = MapStatusUpdateFactory.zoomTo(10.0f); mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(new LatLng(31.083236, 121.394725))); mBaiduMap.animateMapStatus(u); b.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { heatmap.removeHeatMap(); // for(String name:map2.keySet()){ // LatLng ptCenter=new LatLng(map2.get(name)[0],map2.get(name)[1]); // mBaiduMap.addOverlay(new MarkerOptions().position(ptCenter) // .icon(BitmapDescriptorFactory // // .fromResource(R.drawable.shit)).perspective(true)); // } } }); c.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (heatmap != null) heatmap.removeHeatMap(); int time = 0; switch (n.getValue()) { case 0: time = 4; break; case 1: time = 8; break; case 2: time = 10; break; case 3: time = 16; break; case 4: time = 18; break; case 5: time = 22; break; } // int[] DEFAULT_GRADIENT_COLORS = {Color.rgb(255, 255, 0),Color.rgb(255, // 200, 0),Color.rgb(255, 155, 0) ,Color.rgb(255, 100, 0),Color.rgb(255, 55, // 0),Color.rgb(255, 0, 0) }; int[] DEFAULT_GRADIENT_COLORS = {Color.rgb(255, 255, 0), Color.rgb(255, 0, 0)}; // 设置渐变颜色起始值 float[] DEFAULT_GRADIENT_START_POINTS = {0.2f, 1f}; // float[] DEFAULT_GRADIENT_START_POINTS = { 0f,0.2f, 0.4f,0.6f,0.8f,1f // }; // 构造颜色渐变对象1 List<WeightedLatLng> l = new ArrayList<WeightedLatLng>(); for (String n : map.keySet()) { if (!map2.containsKey(n) | !map.get(n).containsKey(time)) { Log.e(TAG, n); continue; } WeightedLatLng ll = new WeightedLatLng( new LatLng(map2.get(n)[0], map2.get(n)[1]), map.get(n).get(time)); l.add(ll); } Gradient gradient = new Gradient(DEFAULT_GRADIENT_COLORS, DEFAULT_GRADIENT_START_POINTS); heatmap = new HeatMap.Builder().weightedData(l).gradient(gradient).radius(20).build(); // 在地图上添加热力图 mBaiduMap.addHeatMap(heatmap); } }); // 设置渐变颜色值 }
/** 初始化界面部件 */ public void initWidget() { locationImg = (ImageButton) findViewById(R.id.main_location); mCurrentMode = LocationMode.NORMAL; locationImg.setImageResource(R.drawable.main_icon_location); OnClickListener btnClickListener = new OnClickListener() { public void onClick(View v) { switch (mCurrentMode) { case NORMAL: // 开启方向传感器 myOrientationListener.start(); locationImg.setImageResource(R.drawable.main_icon_follow); mCurrentMode = LocationMode.FOLLOWING; mBaiduMap.setMyLocationConfigeration( new MyLocationConfiguration(mCurrentMode, true, null)); // BitmapDescriptor mCurrentMarker = BitmapDescriptorFactory // .fromResource(R.drawable.navi_map_gps_locked); // MyLocationConfiguration config = new // MyLocationConfiguration( // mCurrentMode, true, mCurrentMarker); // mBaiduMap.setMyLocationConfigeration(config); break; case COMPASS: // 关闭方向传感器 myOrientationListener.stop(); locationImg.setImageResource(R.drawable.main_icon_location); mCurrentMode = LocationMode.NORMAL; mBaiduMap.setMyLocationConfigeration( new MyLocationConfiguration(mCurrentMode, true, null)); MapStatus ms = new MapStatus.Builder(mBaiduMap.getMapStatus()).overlook(0).rotate(0).build(); MapStatusUpdate u = MapStatusUpdateFactory.newMapStatus(ms); mBaiduMap.animateMapStatus(u); break; case FOLLOWING: locationImg.setImageResource(R.drawable.main_icon_compass); mCurrentMode = LocationMode.COMPASS; mBaiduMap.setMyLocationConfigeration( new MyLocationConfiguration(mCurrentMode, true, null)); // BitmapDescriptor mCurrentMarker0 = // BitmapDescriptorFactory // .fromResource(R.drawable.navi_map_gps_locked); // MyLocationConfiguration config0 = new // MyLocationConfiguration( // mCurrentMode, true, mCurrentMarker0); // mBaiduMap.setMyLocationConfigeration(config0); break; } } }; locationImg.setOnClickListener(btnClickListener); /** zoom init a origin zoom level maxLevel*0.85 . But it doesn't work */ zoomInButton = (ImageButton) findViewById(R.id.main_zoom_in); zoomOutButton = (ImageButton) findViewById(R.id.main_zoom_out); zoomLevel = (float) (mBaiduMap.getMaxZoomLevel() * 0.85); MapStatusUpdate u = MapStatusUpdateFactory.zoomTo(zoomLevel); mBaiduMap.animateMapStatus(u); OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(View view) { if (view.equals(zoomInButton)) { perfomZoom(true); } else if (view.equals(zoomOutButton)) { perfomZoom(false); } } }; zoomInButton.setOnClickListener(onClickListener); zoomOutButton.setOnClickListener(onClickListener); mButtonNearBy = (MainWidgetImageButton) findViewById(R.id.main_bottombutton_nearby); mButtonRoute = (MainWidgetImageButton) findViewById(R.id.main_bottombutton_route); mButtonNav = (MainWidgetImageButton) findViewById(R.id.main_bottombutton_nav); mButtonMine = (MainWidgetImageButton) findViewById(R.id.main_bottombutton_mine); OnClickListener onBottomButtonClickListener = new OnClickListener() { @Override public void onClick(View view) { try { switch (view.getId()) { case R.id.main_bottombutton_nearby: Intent nearbyIntent = new Intent(MainActivity.this, NearbyActivity.class); startActivity(nearbyIntent); break; case R.id.main_bottombutton_route: Log.i("MainActivity", "Click _route"); Intent searchIntent = new Intent(MainActivity.this, RoutePlanActivity.class); startActivity(searchIntent); break; case R.id.main_bottombutton_nav: Intent mineIntent = new Intent(MainActivity.this, UserActivity.class); startActivity(mineIntent); break; case R.id.main_bottombutton_mine: Intent settingIntent = new Intent(MainActivity.this, SettingActivity.class); startActivity(settingIntent); break; } } catch (Exception e) { e.printStackTrace(); } } }; mButtonNearBy.setOnClickListener(onBottomButtonClickListener); mButtonRoute.setOnClickListener(onBottomButtonClickListener); mButtonNav.setOnClickListener(onBottomButtonClickListener); mButtonMine.setOnClickListener(onBottomButtonClickListener); mSearchImageButton = (ImageButton) findViewById(R.id.main_topView_voice); mSearchImageButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO 语音输入 并跳转到SearchActivity 传入 searchKey if (!NetWorkUtil.isNetWorkConnected(getApplicationContext())) { Toast.makeText(getApplicationContext(), "网络未连接", Toast.LENGTH_SHORT).show(); return; } cancel(); switch (status) { case STATUS_None: start(); status = STATUS_WaitingReady; break; case STATUS_WaitingReady: cancel(); status = STATUS_None; break; case STATUS_Ready: cancel(); status = STATUS_None; break; case STATUS_Speaking: stop(); status = STATUS_Recognition; break; case STATUS_Recognition: cancel(); status = STATUS_None; break; } } }); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_02, container, false); // requestLocButton = (Button) findViewById(R.id.button1); mCurrentMode = LocationMode.NORMAL; // requestLocButton.setText("普通"); // OnClickListener btnClickListener = new OnClickListener() { // public void onClick(View v) { // switch (mCurrentMode) { // case NORMAL: // requestLocButton.setText("跟随"); // mCurrentMode = LocationMode.FOLLOWING; // mBaiduMap // .setMyLocationConfigeration(new MyLocationConfiguration( // mCurrentMode, true, mCurrentMarker)); // break; // case COMPASS: // requestLocButton.setText("普通"); // mCurrentMode = LocationMode.NORMAL; // mBaiduMap // .setMyLocationConfigeration(new MyLocationConfiguration( // mCurrentMode, true, mCurrentMarker)); // break; // case FOLLOWING: // requestLocButton.setText("罗盘"); // mCurrentMode = LocationMode.COMPASS; // mBaiduMap // .setMyLocationConfigeration(new MyLocationConfiguration( // mCurrentMode, true, mCurrentMarker)); // break; // } // } // }; // requestLocButton.setOnClickListener(btnClickListener); // // RadioGroup group = (RadioGroup) this.findViewById(R.id.radioGroup); // radioButtonListener = new OnCheckedChangeListener() { // @Override // public void onCheckedChanged(RadioGroup group, int checkedId) { // if (checkedId == R.id.defaulticon) { // // 传入null则,恢复默认图标 // mCurrentMarker = null; // mBaiduMap // .setMyLocationConfigeration(new MyLocationConfiguration( // mCurrentMode, true, null)); // } // if (checkedId == R.id.customicon) { // // 修改为自定义marker // mCurrentMarker = BitmapDescriptorFactory // .fromResource(R.drawable.ic_launcher); // mBaiduMap // .setMyLocationConfigeration(new MyLocationConfiguration( // mCurrentMode, true, mCurrentMarker)); // } // } // }; // group.setOnCheckedChangeListener(radioButtonListener); // 地图初始化 mMapView = (MapView) view.findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); // 开启定位图层 mBaiduMap.setMyLocationEnabled(true); // 设置地图的视图的大小 MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(18.0f); mBaiduMap.setMapStatus(msu); initOverlay(); // 定位初始化 mLocClient = new LocationClient(MyApplication.getContext()); mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); // 打开gps option.setCoorType("bd09ll"); // 设置坐标类型 option.setScanSpan(1000); mLocClient.setLocOption(option); mLocClient.start(); // marker的点击事件 mBaiduMap.setOnMarkerClickListener( new OnMarkerClickListener() { public boolean onMarkerClick(final Marker marker) { // Toast.makeText(MyApplication.getContext(), "text", Toast.LENGTH_SHORT).show(); // onclListener.onClic(); Button button = new Button(MyApplication.getContext()); button.setBackgroundResource(R.drawable.popup); //// OnInfoWindowClickListener listener = null; // if (marker == mMarkerA || marker == mMarkerB|| marker == mMarkerC|| marker == // mMarkerD) { button.setText("到这里去"); button.setTextColor(android.graphics.Color.BLACK); button.setOnClickListener( new OnClickListener() { public void onClick(View v) { // 此处写button点击事件 Intent intent = new Intent(MyApplication.getContext(), RoutePlanDemo.class); intent.putExtra("x1", marker.getPosition().latitude); intent.putExtra("y1", marker.getPosition().longitude); intent.putExtra("x2", x2); intent.putExtra("y2", y2); mBaiduMap.hideInfoWindow(); startActivity(intent); } }); // listener = new OnInfoWindowClickListener() { // public void onInfoWindowClick() { // LatLng ll = marker.getPosition(); // LatLng llNew = new LatLng(ll.latitude + 0.005, // ll.longitude + 0.005); // 设置marker的地点为新的地点 // marker.setPosition(llNew); // mBaiduMap.hideInfoWindow(); // } // }; // LatLng ll = marker.getPosition(); // mInfoWindow = new InfoWindow(BitmapDescriptorFactory.fromView(button), ll, -47, // listener); // mBaiduMap.showInfoWindow(mInfoWindow); // } else if (marker == mMarkerB) { // button.setText("更改图标"); // button.setOnClickListener(new OnClickListener() { // public void onClick(View v) { // marker.setIcon(bd); // Toast.makeText(MyApplication.getContext(), "text222", // Toast.LENGTH_SHORT).show(); mBaiduMap.hideInfoWindow(); LatLng ll = marker.getPosition(); mInfoWindow = new InfoWindow(button, ll, -47); mBaiduMap.showInfoWindow(mInfoWindow); // } // }); // LatLng ll = marker.getPosition(); // mInfoWindow = new InfoWindow(button, ll, -47); // mBaiduMap.showInfoWindow(mInfoWindow); // } // else if (marker == mMarkerC) { // button.setText("删除"); // button.setOnClickListener(new OnClickListener() { // public void onClick(View v) { // marker.remove(); // mBaiduMap.hideInfoWindow(); // } // }); // LatLng ll = marker.getPosition(); // mInfoWindow = new InfoWindow(button, ll, -47); // mBaiduMap.showInfoWindow(mInfoWindow); // } return true; } }); return view; }