@Override public void init() { // 设置是否显示比例尺控件 mapView.showScaleControl(true); // 设置是否显示缩放控件 mapView.showZoomControls(false); baiduMap = mapView.getMap(); // 设置监听 baiduMap.setOnMapClickListener( new OnMapClickListener() { @Override public boolean onMapPoiClick(MapPoi mapPoi) { return false; } @Override public void onMapClick(final LatLng latLng) { System.out.println(latLng.latitude + "--" + latLng.longitude); geoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(latLng)); showWaiting(true); ok.setEnabled(false); markFirstLocation(); markClickLocation(latLng); } }); // 检索 geoCoder = GeoCoder.newInstance(); geoCoder.setOnGetGeoCodeResultListener(getGeoCoderResultListener); // 开始定位 client = new LocationClient(getApplicationContext()); client.setLocOption(getDefaultLocationClientOption()); client.registerLocationListener(dbListener); client.start(); // waiting的layout的初始化 waitingAnimation = AnimationUtils.loadAnimation(SelectLocationActivity.this, R.anim.anim_waiting); waitingIcon.setAnimation(waitingAnimation); showWaiting(true); // 位置列表初始化 adapter = new LocationAdapter(); locationListView.setAdapter(adapter); locationListView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { locationList.get(currentLocation).setSelected(false); locationList.get(position).setSelected(true); currentLocation = position; adapter.notifyDataSetChanged(); // 重置标志 markFirstLocation(); markClickLocation(locationList.get(position).getLatLng()); } }); // 按钮 back.setOnClickListener(clickListener); ok.setOnClickListener(clickListener); ok.setEnabled(false); Log.e("tag", "---------------------create---------------------------"); }
/** * 从view 得到图片 * * @param view * @return */ public BMapUtil(Activity context) { try { mContext = context; mSearch = GeoCoder.newInstance(); mSearch.setOnGetGeoCodeResultListener(this); } catch (Exception e) { e.printStackTrace(); } }
private void initBaiduMap() { mapView = (MapView) findViewById(R.id.bmapView); baiduMap = mapView.getMap(); baiduMap.setMaxAndMinZoomLevel(18, 13); IntentFilter iFilter = new IntentFilter(); iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR); iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR); receiver = new BaiduReceiver(); registerReceiver(receiver, iFilter); geoCoder = GeoCoder.newInstance(); geoCoder.setOnGetGeoCodeResultListener(this); Intent intent = getIntent(); intentType = intent.getStringExtra(TYPE); initActionBar(R.string.chat_position); if (intentType.equals(TYPE_SELECT)) { // 选择发送位置 // 开启定位图层 baiduMap.setMyLocationEnabled(true); baiduMap.setMyLocationConfigeration( new MyLocationConfigeration(MyLocationConfigeration.LocationMode.NORMAL, true, null)); // 定位初始化 locClient = new LocationClient(this); locClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.setProdName("avosim"); option.setOpenGps(true); option.setCoorType("bd09ll"); option.setScanSpan(1000); option.setOpenGps(true); option.setIsNeedAddress(true); option.setIgnoreKillProcess(true); locClient.setLocOption(option); locClient.start(); if (locClient != null && locClient.isStarted()) { locClient.requestLocation(); } if (lastLocation != null) { // 显示在地图上 LatLng ll = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude()); MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll); baiduMap.animateMapStatus(u); } } else { Bundle b = intent.getExtras(); LatLng latlng = new LatLng(b.getDouble(LATITUDE), b.getDouble(LONGITUDE)); // 维度在前,经度在后 baiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(latlng)); OverlayOptions ooA = new MarkerOptions().position(latlng).icon(descriptor).zIndex(9); baiduMap.addOverlay(ooA); } }
@Override public boolean onMarkerClick(final Marker marker) { if (marker != null) { final LatLng latLng = marker.getPosition(); if (latLng != null && mGeoCoder == null) { final ReverseGeoCodeOption reverseGeoCodeOption = new ReverseGeoCodeOption(); reverseGeoCodeOption.location(latLng); mGeoCoder = GeoCoder.newInstance(); mGeoCoder.setOnGetGeoCodeResultListener(this); if (!mGeoCoder.reverseGeoCode(reverseGeoCodeOption)) mGeoCoder = null; } } return false; }
private void initview() { outmap = (ImageView) findViewById(R.id.outmap); back = (LinearLayout) findViewById(R.id.map2_back); mylocation = (ImageView) findViewById(R.id.mylocation); mMapView = (MapView) findViewById(R.id.map2); mBaiduMap = mMapView.getMap(); // 初始化搜索模块,注册事件监听 msearch2 = GeoCoder.newInstance(); msearch2.setOnGetGeoCodeResultListener(this); outmap.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { showPopupWindow(-126, 24); } }); back.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); mylocation.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { CenterToMyLocation(); } }); data = new ArrayList<Map<String, Object>>(); Map<String, Object> map = new HashMap<>(); map.put("name", "百度地图"); data.add(map); Map<String, Object> map2 = new HashMap<>(); map2.put("name", "高德地图"); data.add(map2); }
private void initBaiduMap() { mMapView = (MapView) findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); mBaiduMap.setMaxAndMinZoomLevel(18, 13); IntentFilter iFilter = new IntentFilter(); iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR); iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR); mReceiver = new BaiduReceiver(); registerReceiver(mReceiver, iFilter); Intent intent = getIntent(); String type = intent.getStringExtra("type"); if (type.equals("select")) { // 聊天选择位置 initTopBarForBoth( "我的位置", R.drawable.base_action_bar_true_bg_selector, new onRightImageButtonClickListener() { @Override public void onClick() { goToChatPage(); Log.i("地图", "点击确定"); } }); // 获取位置后再设置为可点击 mHeadLayout.getRightImageButton().setEnabled(false); initLocClient(); } else { // 查看当前位置 initTopBarForLeft("位置"); Bundle b = intent.getExtras(); LatLng latlng = new LatLng(b.getDouble("latitude"), b.getDouble("longitude")); mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(latlng)); // 显示当前位置图标 OverlayOptions ooA = new MarkerOptions().position(latlng).icon(bdgeo).zIndex(9); mBaiduMap.addOverlay(ooA); } mSearch = GeoCoder.newInstance(); mSearch.setOnGetGeoCodeResultListener(this); }
@Override public void onReceiveLocation(BDLocation location) { // TODO Auto-generated method stub if (null != location && (location.getLocType() == BDLocation.TypeGpsLocation || location.getLocType() == BDLocation.TypeNetWorkLocation)) { System.out.println( "================>" + location.getLocType() + BDLocation.TypeOffLineLocation); StringBuffer sb = new StringBuffer(256); sb.append("time : "); sb.append(location.getTime()); sb.append("\nlatitude : "); sb.append(location.getLatitude()); sb.append("\nlontitude : "); sb.append(location.getLongitude()); sb.append("\naddr : "); sb.append(location.getAddrStr()); System.out.println(sb.toString()); // 第一次去的的经纬度 firstLocationLatitude = location.getLatitude(); firstLocationLongitude = location.getLongitude(); // 设置位置 MyLocationData locData = new MyLocationData.Builder() .accuracy(location.getRadius()) .direction(10) .latitude(location.getLatitude()) .longitude(location.getLongitude()) .build(); baiduMap.setMyLocationData(locData); // 更新位置、比例系数、添加标志等状态 LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); markFirstLocation(); markClickLocation(latLng); // 更新地图状态 MapStatus mapStatus = new MapStatus.Builder().target(latLng).zoom(16).build(); MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mapStatus); baiduMap.animateMapStatus(mapStatusUpdate); // 检索 geoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(latLng)); // 停止定位 client.stop(); } else { // 定位失败 showToast("定位失败,请检查网络,重新定位"); SelectLocationActivity.this.setResult(RESULT_CANCELED); SelectLocationActivity.this.finish(); } }
@Override public void onGetReverseGeoCodeResult(final ReverseGeoCodeResult result) { mGeoCoder.destroy(); mGeoCoder = null; String address = getString(R.string.address_failed); if (result != null && result.error == SearchResult.ERRORNO.NO_ERROR) address = result.getAddress(); final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setTitle(R.string.address); alertDialog.setMessage(address); alertDialog.setPositiveButton(R.string.confirm, null); alertDialog.show(); }
@Override protected void onDestroy() { if (mMapView != null) mMapView.onDestroy(); if (mHandler != null) mHandler.removeCallbacks(this); if (mRoutePlanSearch != null) mRoutePlanSearch.destroy(); if (mGeoCoder != null) mGeoCoder.destroy(); if (mLocationClient != null) mLocationClient.stop(); mThreadPool.close(); super.onDestroy(); exit(); }
/** * 发起搜索 * * @param v */ public void SearchButtonProcess(String city, String address) { // Geo搜索 mSearch.geocode(new GeoCodeOption().city(city).address(address)); }
private void GERSearch() { msearch2.geocode(new GeoCodeOption().city("成都").address(endaddress)); }