Browse Source

气泡功能咖啡

huyuguo 5 years ago
parent
commit
b54a935e28

+ 67 - 3
app/src/main/java/com/electric/chargingpile/activity/MainMapActivity.java

171
171
172
public class MainMapActivity extends Activity implements LocationSource, AMapLocationListener,
172
public class MainMapActivity extends Activity implements LocationSource, AMapLocationListener,
173
        View.OnClickListener, AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMapClickListener,
173
        View.OnClickListener, AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMapClickListener,
174
        ClusterRender, ClusterClickListener, WeatherSearch.OnWeatherSearchListener, EasyPermissions.PermissionCallbacks {
174
        ClusterRender, ClusterClickListener, WeatherSearch.OnWeatherSearchListener, EasyPermissions.PermissionCallbacks,
175
        AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener {
175
    private static final String TAG = "MainMapActivity";
176
    private static final String TAG = "MainMapActivity";
176
    public static String screen_jing = "", screen_wei = "";
177
    public static String screen_jing = "", screen_wei = "";
177
    public static String location_city = "";
178
    public static String location_city = "";
736
            }
737
            }
737
        }
738
        }
738
    };
739
    };
740
    private View infoWindow;
739
741
740
742
741
    @Override
743
    @Override
1483
        aMap.setOnCameraChangeListener(this);
1485
        aMap.setOnCameraChangeListener(this);
1484
        aMap.setLocationSource(this);// 设置定位监听
1486
        aMap.setLocationSource(this);// 设置定位监听
1485
        aMap.setOnMapClickListener(this);
1487
        aMap.setOnMapClickListener(this);
1488
        aMap.setOnMarkerClickListener(this);
1489
        aMap.setInfoWindowAdapter(this);
1490
        aMap.setOnInfoWindowClickListener(this);
1486
        aMap.setOnMapLoadedListener(this);// 设置amap加载成功事件监听器
1491
        aMap.setOnMapLoadedListener(this);// 设置amap加载成功事件监听器
1487
        aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
1492
        aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
1488
        aMap.getUiSettings().setZoomControlsEnabled(false);// 设置默认缩放按钮是否显示
1493
        aMap.getUiSettings().setZoomControlsEnabled(false);// 设置默认缩放按钮是否显示
3398
        }
3403
        }
3399
    }
3404
    }
3400
3405
3406
    @Override
3407
    public boolean onMarkerClick(Marker marker) {
3408
        return false;
3409
    }
3410
3411
    /**
3412
     * 监听自定义infowindow窗口的infowindow时间回调
3413
     * add by huyuguo
3414
     * @param marker
3415
     * @return
3416
     */
3417
    @Override
3418
    public View getInfoWindow(Marker marker) {
3419
        if (infoWindow == null) {
3420
            infoWindow = getLayoutInflater().inflate(R.layout.custom_info_window, null);
3421
        }
3422
        return infoWindow;
3423
    }
3424
3425
    @Override
3426
    public View getInfoContents(Marker marker) {
3427
        return null;
3428
    }
3429
3430
    /**
3431
     * 自定义infowindow窗口
3432
     * 如果想修改自定义Infow中内容,请通过view找到它并修改
3433
     */
3434
    public void updateInfoWindow(String text) {
3435
        if (nMarker == null) {
3436
            return;
3437
        }
3438
3439
        if (infoWindow == null) {
3440
            return;
3441
        }
3442
3443
        TextView distance = infoWindow.findViewById(R.id.distance);
3444
        distance.setText(text);
3445
3446
    }
3447
3448
    /**
3449
     * 点击自定义气泡,进行导航操作
3450
     * @param marker
3451
     */
3452
    @Override
3453
    public void onInfoWindowClick(Marker marker) {
3454
        ToastUtil.showToast(getApplicationContext(), "sdsfsdf", Toast.LENGTH_SHORT);
3455
    }
3456
3401
    public class ZhanAdapter extends BaseAdapter {
3457
    public class ZhanAdapter extends BaseAdapter {
3402
        @Override
3458
        @Override
3403
        public int getCount() {
3459
        public int getCount() {
4914
//            Log.d(TAG, "onClick: latitude=" + position.latitude + "   long=" + position.longitude + "\n" + ((RegionItem) clusterItem).getChargePoint().toString());
4970
//            Log.d(TAG, "onClick: latitude=" + position.latitude + "   long=" + position.longitude + "\n" + ((RegionItem) clusterItem).getChargePoint().toString());
4915
            Long zhan_id = ((RegionItem) clusterItem).getChargePoint().getId();
4971
            Long zhan_id = ((RegionItem) clusterItem).getChargePoint().getId();
4916
            nMarker = marker;
4972
            nMarker = marker;
4973
4974
            // add by hyg 显示气泡
4975
            nMarker.showInfoWindow();
4976
4917
            current_chargePoint = chargePoint;
4977
            current_chargePoint = chargePoint;
4918
            dialog.show();
4978
            dialog.show();
4919
            if (null != marker.getPosition()) {
4979
            if (null != marker.getPosition()) {
5005
                latLng = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing));
5065
                latLng = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing));
5006
            }
5066
            }
5007
5067
5008
            //OK
5068
            // OK
5009
            double d = AMapUtils.calculateLineDistance(center, latLng);
5069
            double d = AMapUtils.calculateLineDistance(center, latLng);
5010
            if ("0m".equals(Util.getDistance(d))) {
5070
            if ("0m".equals(Util.getDistance(d))) {
5011
                windowDistance.setText("未知");
5071
                windowDistance.setText("未知");
5072
                updateInfoWindow("未知距离");
5012
            } else {
5073
            } else {
5013
                windowDistance.setText(Util.getDistance(d));
5074
                String text = Util.getDistance(d);
5075
                windowDistance.setText(text);
5076
                updateInfoWindow("距您 " + text);
5014
            }
5077
            }
5078
5015
        }
5079
        }
5016
5080
5017
        String acNum = null, dcNum = null, acableNum = null, dcableNum = null;
5081
        String acNum = null, dcNum = null, acableNum = null, dcableNum = null;

BIN
app/src/main/res/drawable-hdpi/custom_info_window_bg.9.png


+ 47 - 0
app/src/main/res/layout/custom_info_window.xml

1
<?xml version="1.0" encoding="utf-8"?>
2
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
4
    xmlns:tools="http://schemas.android.com/tools"
5
    android:layout_width="wrap_content"
6
    android:layout_height="wrap_content"
7
    android:background="@drawable/custom_info_window_bg"
8
    android:layout_marginRight="20dp">
9
10
    <LinearLayout
11
        android:layout_width="wrap_content"
12
        android:layout_height="40dp"
13
        android:gravity="center"
14
        app:layout_constraintBottom_toBottomOf="parent"
15
        app:layout_constraintLeft_toLeftOf="parent"
16
        app:layout_constraintRight_toRightOf="parent"
17
        app:layout_constraintTop_toTopOf="parent">
18
19
        <TextView
20
            android:id="@+id/distance"
21
            android:layout_width="wrap_content"
22
            android:layout_height="wrap_content"
23
            android:text="距您 ..."
24
            android:textColor="@color/white"
25
            android:textSize="13dp" />
26
27
        <View
28
            android:layout_width="0.5dp"
29
            android:layout_height="15dp"
30
            android:layout_marginLeft="5dp"
31
            android:layout_marginRight="5dp"
32
            android:background="@color/white" />
33
34
        <ImageView
35
            android:layout_width="wrap_content"
36
            android:layout_height="wrap_content"
37
            android:layout_marginRight="2dp"
38
            android:src="@drawable/navigation_white_icon" />
39
40
        <TextView
41
            android:layout_width="wrap_content"
42
            android:layout_height="wrap_content"
43
            android:text="导航"
44
            android:textColor="@color/white"
45
            android:textSize="13dp" />
46
    </LinearLayout>
47
</android.support.constraint.ConstraintLayout>