LLLTTTTTT

    xiaoxiao2021-03-25  51

    package com.kesen.fire.views.activity;

    import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageButton; import android.widget.TextView;

    import com.amap.api.location.AMapLocation; import com.amap.api.location.AMapLocationClient; import com.amap.api.location.AMapLocationClientOption; import com.amap.api.location.AMapLocationListener; import com.amap.api.maps.AMap; import com.amap.api.maps.CameraUpdateFactory; import com.amap.api.maps.LocationSource; import com.amap.api.maps.MapView; import com.amap.api.maps.model.BitmapDescriptorFactory; import com.amap.api.maps.model.LatLng; import com.amap.api.maps.model.LatLngBounds; import com.amap.api.maps.model.Marker; import com.amap.api.maps.model.MarkerOptions; import com.amap.api.maps.model.PolylineOptions; import com.kesen.fire.R; import com.kesen.fire.core.BaseToolbarActivity;

    import butterknife.Bind;

    /** * Created by liqing on 17/3/9. */ public class LLLLTTT extends BaseToolbarActivity implements AMapLocationListener ,AMap.OnMapLoadedListener,LocationSource ,AMap.OnMarkerClickListener,AMap.InfoWindowAdapter {

    public static String PROVENCE = "山东"; public static String CITY_NAME = "青岛"; public static double LATITUDE = 0.0; public static double LONGITUDE = 0.0; public static String POI_NAME = "未知"; private LatLng location; AMap aMap; private Marker marker; //声明mLocationOption对象 private AMapLocationClient mlocationClient; private AMapLocationClientOption mLocationOption; //声明回调监听器 private OnLocationChangedListener mOnLocationChangedListener; private AMap.OnMapLoadedListener mOnMapLoadListener; @Bind(R.id.eqstr_map_bar) MapView mapView; @Override protected void initViews(Bundle savedInstanceState) { //mapview mapView.onCreate(savedInstanceState); System.out.println("initViews"); System.out.println("initViews"); //初始化地图控制器对象 if (aMap == null) { aMap = mapView.getMap(); } // 设置定位监听 aMap.setLocationSource(this); //设置MapLoadedListener();回调 onMapLocated() //aMap.setOnMapLoadedListener(this); aMap.getUiSettings().setMyLocationButtonEnabled(true);//设置默认定位按钮是否显示 aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false // 设置定位的类型为定位模式,参见类AMap。 aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE); // 设置为true表示系统定位按钮显示并响应点击,false表示隐藏,默认是false aMap.setMyLocationEnabled(true); aMap.setOnMapLoadedListener(this); mlocationClient = new AMapLocationClient(getApplicationContext()); mlocationClient.setLocationListener(this); // 绑定 Marker 被点击事件 //aMap.setOnMarkerClickListener(markerClickListener); aMap.setOnMarkerClickListener(this); //实现 InfoWindow 样式和内容,必须要先执行如下方法: aMap.setInfoWindowAdapter(this);//AMap类中

    // mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); // mLocationOption.setOnceLocation(true); //设置定位参数 mlocationClient.setLocationOption(mLocationOption); mlocationClient.startLocation();

    } @Override protected void initListeners() { } @Override protected void initData() { //setTitle(getString(R.string.equip_str)); }

    // mlocationClient = new AMapLocationClient(this); 初始化定位参数 // mLocationOption = new AMapLocationClientOption(); 设置定位监听 // mlocationClient.setLocationListener(this); //

    // 定位成功后回调 @Override public void onLocationChanged(AMapLocation arg0) { if (arg0 != null && mOnLocationChangedListener != null) { if (arg0.getErrorCode() == 0 && arg0 != null) { //等于0是成功了 System.out.println("城市:" + arg0.getCity() + "电话区号" + arg0.getCityCode()); System.out.println("jingweidu" + arg0.getLatitude() + "wei" + arg0.getAltitude()); location = new LatLng(Double.valueOf(arg0.getLatitude()), Double.valueOf(arg0.getLongitude())); System.out.println("eslatlng-before==" + location); this.PROVENCE = arg0.getProvince(); this.CITY_NAME = arg0.getCity(); this.POI_NAME = arg0.getPoiName(); this.LATITUDE = arg0.getLatitude(); this.LONGITUDE = arg0.getLongitude(); //CameraUpdateFactory.newLatLngZoom(location, 13) aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 15)); } else { Log.d("tag", "onLocation2"); String errText = "定位失败," + arg0.getErrorCode() + ": " + arg0.getErrorInfo(); //showToast(errText); aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 13)); System.out.println("LLLLLTTTTT定位失败"); } } } @Override protected int getLayoutId() { return R.layout.activity_equipstrength; } /** * 方法必须重写 */ @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mapView.onSaveInstanceState(outState); } /** * 方法必须重写 */ @Override protected void onDestroy() { super.onDestroy(); mapView.onDestroy();

    // eqStrParentPresenter.detachView(); // eqStrLeafPresenter.detachView(); // mQueuePresenter.detachView(); // presenter.detachView(); if (null != mlocationClient) { mlocationClient.onDestroy(); } }

    //AMap.OnMapLoadedListener的回调 @Override public void onMapLoaded() { //地图加载完成后回调 :加载marker //绘制marker System.out.println("onMapLoaded()"); LatLngBounds bounds = new LatLngBounds .Builder() .include(location) .build(); aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10)); addMarkerToMap(location);

    // if(mOnMapLoadListener!=null){ // System.out.println(“mOnMapLoadListener!=null”); // LatLngBounds bounds = new LatLngBounds.Builder() // .include(location).build(); // aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10)); // addMarkerToMap(location); // }else{ // System.out.println(“mOnMapLoadListener====null”); // }

    // LatLngBounds bounds = new LatLngBounds.Builder() // .include(location).build(); // aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10)); // addMarkerToMap(location); System.out.println(“addMarkerToMap endddd”);

    // 绘制曲线 aMap.addPolyline((new PolylineOptions()) .add(new LatLng(43.828, 87.621), new LatLng(45.808, 126.55)) .geodesic(true).color(Color.RED)); } private void addMarkerToMap(LatLng mLatng) { // // Bitmap bitmap = convertViewToBitmap(view);

    // marker = // aMap.addMarker(new MarkerOptions() // .position(mLatng) // .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory // .decodeResource(getResources(), R.drawable.es_marker_car))) // .draggable(true)); System.out.println(“addMarkerToMap ssssss”); System.out.println(“addMarkerToMap ssssss”); marker = aMap.addMarker(new MarkerOptions() .position(new LatLng(31.47192, 120.275394)) .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory .decodeResource(getResources(), R.drawable.es_marker_car))) .draggable(true)); }

    //locationSource 提供供位置数据的接口。复写activate (激活定位) deactivate (停止定位)2个方法,实现 @Override public void activate(OnLocationChangedListener onLocationChangedListener) { //激活定位 mOnLocationChangedListener = onLocationChangedListener; if (mlocationClient == null) { System.out.println("activate =======>"); //初始化定位 mlocationClient = new AMapLocationClient(this); //设置定位监听 mlocationClient.setLocationListener(this); //初始化定位参数 mLocationOption = new AMapLocationClientOption(); //设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式 mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); //设置是否返回地址信息(默认返回地址信息) mLocationOption.setNeedAddress(true); //设置是否只定位一次,默认为false mLocationOption.setOnceLocation(true); //设置是否强制刷新WIFI,默认为强制刷新 mLocationOption.setWifiActiveScan(true); //设置是否允许模拟位置,默认为false,不允许模拟位置 mLocationOption.setMockEnable(false); //设置定位间隔,单位毫秒,默认为2000ms // mLocationOption.setInterval(2000); //给定位客户端对象设置定位参数 mlocationClient.setLocationOption(mLocationOption); //启动定位 mlocationClient.startLocation(); } } @Override public void deactivate() { mOnLocationChangedListener = null; if (mlocationClient != null) { mlocationClient.stopLocation(); mlocationClient.onDestroy(); } mlocationClient = null; } @Override protected void onPause() { super.onPause(); mapView.onPause(); deactivate(); } //AMap.OnMarkerClickListener的回调 @Override public boolean onMarkerClick(Marker marker) { //调用 Marker 类的 showInfoWindow() 和 hideInfoWindow() 方法可以控制显示和隐藏。 System.out.println("onMarkerClick"); marker.showInfoWindow(); System.out.println("onMarkerClick marker.showInfoWindow()"); return true; } //点击Marker -->showInfoWindown -->implement InfoWindowAdapter去自定义infowindown @Override public View getInfoWindow(Marker marker) { System.out.println("getInfoWindow"); View infoWindow = null; if (infoWindow == null) { infoWindow = LayoutInflater.from(this).inflate( R.layout.es_parent_popu, null); } render(marker, infoWindow); return infoWindow; } /** * 自定义infowinfow窗口 */ public void render(final Marker marker, View view) {

    //如果想修改自定义Infow中内容,请通过view找到它并修改 TextView title =(TextView)view.findViewById(R.id.title); title.setText(“lqteam”); TextView snippet =(TextView)view.findViewById(R.id.snippet); String str =”I love you “; snippet.setText(str); ImageButton button =(ImageButton)view.findViewById(R.id.start_amap_app); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (marker!=null){ marker.hideInfoWindow(); } } });

    // TextView title = (TextView) viewp.findViewById(R.id.title); // title.setText(eqStrParentBeanA.names);//esNodeName // // TextView snippet = (TextView) viewp.findViewById(R.id.snippet); // String str = “大队总数:”+ eqStrParentBeanA.firecount.dd+”\n”+”执勤中队总数:”+eqStrParentBeanA.firecount.zd+”,”+ // “备防人员总数:”+eqStrParentBeanA.firecount.staff+”\n”+”备防车辆总数:”+eqStrParentBeanA.firecount.carnum+”,”+ // “总载水量:”+eqStrParentBeanA.firecount.water+”吨\n”+”总泡沫量:”+eqStrParentBeanA.firecount.fram+”吨,”+”总干粉量:”+ // eqStrParentBeanA.firecount.powfoam+”吨\n”; // snippet.setText(str);//marker.getSnippet() // ImageButton button = (ImageButton) viewp // .findViewById(R.id.start_amap_app); // // 调起高德地图app // button.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // if (currentMarker != null) { // currentMarker.hideInfoWindow(); // } // } // });

    } @Override public View getInfoContents(Marker marker) { return null; }

    }

    转载请注明原文地址: https://ju.6miu.com/read-50222.html

    最新回复(0)