Skip to content

Commit

Permalink
修复了悬浮地图、历史记录、主界面三者位置有可能不一致的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCShou committed Sep 30, 2021
1 parent 1acfe46 commit 34b2dee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
33 changes: 19 additions & 14 deletions app/src/main/java/com/zcshou/joystick/JoyStick.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public void show() {
mWindowManager.removeView(mHistoryLayout);
}
if (mMapLayout.getParent() == null) {
resetBaiduMap();
mWindowManager.addView(mMapLayout, mWindowParamMap);
}
break;
Expand Down Expand Up @@ -394,13 +395,11 @@ private void initJoyStickMapView() {
}
});
mSearchList.setOnItemClickListener((parent, view, position, id) -> {
String lng = ((TextView) view.findViewById(R.id.poi_longitude)).getText().toString();
String lat = ((TextView) view.findViewById(R.id.poi_latitude)).getText().toString();
LatLng latLng = new LatLng(Double.parseDouble(lat), Double.parseDouble(lng));

mSearchLayout.setVisibility(View.GONE);

markBaiduMap(latLng);
String lng = ((TextView) view.findViewById(R.id.poi_longitude)).getText().toString();
String lat = ((TextView) view.findViewById(R.id.poi_latitude)).getText().toString();
markBaiduMap(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng)));
});

TextView tips = mMapLayout.findViewById(R.id.joystick_map_tips);
Expand Down Expand Up @@ -448,8 +447,8 @@ public boolean onQueryTextChange(String newText) {
}
});

ImageButton btnOk = mMapLayout.findViewById(R.id.btnGo);
btnOk.setOnClickListener(v -> {
ImageButton btnGo = mMapLayout.findViewById(R.id.btnGo);
btnGo.setOnClickListener(v -> {
// 关闭时清除焦点
mWindowParamMap.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Expand All @@ -468,7 +467,7 @@ public boolean onQueryTextChange(String newText) {

GoUtils.DisplayToast(mContext, "位置已传送");
});
btnOk.setColorFilter(getResources().getColor(R.color.colorAccent, mContext.getTheme()));
btnGo.setColorFilter(getResources().getColor(R.color.colorAccent, mContext.getTheme()));

ImageButton btnClose = mMapLayout.findViewById(R.id.map_close);
btnClose.setOnClickListener(v -> {
Expand Down Expand Up @@ -634,17 +633,23 @@ public boolean onQueryTextChange(String newText) {// 当搜索内容改变时触
mSearchView.onActionViewCollapsed();
tips.setVisibility(VISIBLE);

String wgs84Longitude;
String wgs84Latitude;
//wgs84坐标
// wgs84坐标
String wgs84LatLng = (String) ((TextView) view.findViewById(R.id.WGSLatLngText)).getText();
wgs84LatLng = wgs84LatLng.substring(wgs84LatLng.indexOf("[") + 1, wgs84LatLng.indexOf("]"));
String[] latLngStr2 = wgs84LatLng.split(" ");
wgs84Longitude = latLngStr2[0].substring(latLngStr2[0].indexOf(":") + 1);
wgs84Latitude = latLngStr2[1].substring(latLngStr2[1].indexOf(":") + 1);
String[] wgs84latLngStr = wgs84LatLng.split(" ");
String wgs84Longitude = wgs84latLngStr[0].substring(wgs84latLngStr[0].indexOf(":") + 1);
String wgs84Latitude = wgs84latLngStr[1].substring(wgs84latLngStr[1].indexOf(":") + 1);

mListener.onPositionInfo(Double.parseDouble(wgs84Longitude), Double.parseDouble(wgs84Latitude));

// 注意这里在选择位置之后需要刷新地图
String bdLatLng = (String) ((TextView) view.findViewById(R.id.BDLatLngText)).getText();
bdLatLng = bdLatLng.substring(bdLatLng.indexOf("[") + 1, bdLatLng.indexOf("]"));
String[] bdLatLngStr = bdLatLng.split(" ");
String bdLongitude = bdLatLngStr[0].substring(bdLatLngStr[0].indexOf(":") + 1);
String bdLatitude = bdLatLngStr[1].substring(bdLatLngStr[1].indexOf(":") + 1);
mCurMapLngLat = new LatLng(Double.parseDouble(bdLatitude), Double.parseDouble(bdLongitude));

GoUtils.DisplayToast(mContext, "位置已传送");
});

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/zcshou/service/ServiceGo.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public void setPosition(double lng, double lat) {
mCurLng = lng;
mCurLat = lat;
mLocHandler.sendEmptyMessage(HANDLER_MSG_ID);
mJoyStick.setCurrentPosition(mCurLng, mCurLat);
}
}
}
Expand Down

0 comments on commit 34b2dee

Please sign in to comment.