diff --git a/app/build.gradle b/app/build.gradle index ddad9ff..3b14d7f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,7 @@ dependencies { implementation 'androidx.navigation:navigation-fragment:2.1.0' implementation 'androidx.navigation:navigation-ui:2.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation files('libs\\jts-1.13.jar') testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/app/libs/jts-1.13.jar b/app/libs/jts-1.13.jar new file mode 100644 index 0000000..bbaa20b Binary files /dev/null and b/app/libs/jts-1.13.jar differ diff --git a/app/src/main/java/com/navinfo/outdoor/api/Constant.java b/app/src/main/java/com/navinfo/outdoor/api/Constant.java index aa4d52d..89232e4 100644 --- a/app/src/main/java/com/navinfo/outdoor/api/Constant.java +++ b/app/src/main/java/com/navinfo/outdoor/api/Constant.java @@ -44,7 +44,6 @@ public class Constant { public static final int FILTER_LIST = 4;//筛选列表所有数据地图显示 public static final int FILTER_LIST_ITEM = 5;//点击筛选的item public static final int GATHER_GET = 6;//点击开始采集 - public static final int GATHER_IS_SLIDING_GET =2;//通知抽屉不收回 public static final int TREASURE_GATHER_GET_WORD = 7;//领取采集页面其他marker 的回传 public static final int MAIN_BUTTON_VISIABLE = 8; // 控制主界面各个按钮显隐状态的what值 public static final int MAIN_HEADER = 9; // 控制主界面各个header @@ -62,6 +61,10 @@ public class Constant { public static String USER_ATTESTATION_NAME; //实名认证姓名 银行卡 + public static int NUMBER =200; //任务个数 + public static String PHOTOGRAPH ="全部"; //任务类型 + public static String EXCLUSIVE ="全部"; + public static String TYPE ="全部"; /** * 用户当前位置 */ diff --git a/app/src/main/java/com/navinfo/outdoor/base/BaseActivity.java b/app/src/main/java/com/navinfo/outdoor/base/BaseActivity.java index ce35758..12c13f9 100644 --- a/app/src/main/java/com/navinfo/outdoor/base/BaseActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/base/BaseActivity.java @@ -8,6 +8,9 @@ import android.os.Bundle; import android.util.DisplayMetrics; import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; import android.widget.Toast; @@ -15,6 +18,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import com.navinfo.outdoor.R; import com.navinfo.outdoor.api.UserApplication; import com.gyf.immersionbar.ImmersionBar; @@ -69,16 +73,16 @@ public abstract class BaseActivity extends AppCompatActivity { return false; }); //loading样式 - //View view = LayoutInflater.from(this).inflate(R.layout.loading_alert, null); - //alertDialog.setView(view); + View view = LayoutInflater.from(this).inflate(R.layout.loading, null); + alertDialog.setView(view); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } public void setLoadingDialogText(String s) { //给loading 添加文字 - /* TextView view = alertDialog.findViewById(R.id.progressBar_tx); - view.setText(s);*/ + TextView view = alertDialog.findViewById(R.id.progressBar_tx); + view.setText(s); } public void dismissLoadingDialog() { diff --git a/app/src/main/java/com/navinfo/outdoor/base/BaseFragment.java b/app/src/main/java/com/navinfo/outdoor/base/BaseFragment.java index aeafb8a..83c7577 100644 --- a/app/src/main/java/com/navinfo/outdoor/base/BaseFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/base/BaseFragment.java @@ -1,5 +1,6 @@ package com.navinfo.outdoor.base; +import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; @@ -7,14 +8,19 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import com.kongzue.dialog.interfaces.OnBackClickListener; +import com.kongzue.dialog.v3.WaitDialog; +import com.navinfo.outdoor.R; import com.navinfo.outdoor.util.BackHandlerHelper; import com.navinfo.outdoor.util.FragmentBackHandler; @@ -66,16 +72,16 @@ public abstract class BaseFragment extends Fragment implements FragmentBackHandl }); //loading样式 - //View view = LayoutInflater.from(this).inflate(R.layout.loading, null); - //alertDialog.setView(view); + View view = LayoutInflater.from(getActivity()).inflate(R.layout.loading, null); + alertDialog.setView(view); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } public void setLoadingDialogText(String s) { //给loading 添加文字 - /* TextView view = alertDialog.findViewById(R.id.progressBar_tx); - view.setText(s);*/ + TextView view = alertDialog.findViewById(R.id.progressBar_tx); + view.setText(s); } public void dismissLoadingDialog() { diff --git a/app/src/main/java/com/navinfo/outdoor/bean/JobSearchBean.java b/app/src/main/java/com/navinfo/outdoor/bean/JobSearchBean.java new file mode 100644 index 0000000..477448a --- /dev/null +++ b/app/src/main/java/com/navinfo/outdoor/bean/JobSearchBean.java @@ -0,0 +1,226 @@ +package com.navinfo.outdoor.bean; + +import java.util.List; + +public class JobSearchBean { + /** + * status : 0 + * msg : 成功 + * body : {"pageNum":0,"list":[{"id":0,"name":"","address":"http://10.130.23.166:8080/cbt/img/blue.png","telephone":11,"geo":"标题11","price":"通过","type":"","dist":""}],"total":100,"pageSize":10,"totalPage":0} + * upload : [] + */ + + private int status; + private String msg; + private BodyBean body; + private List upload; + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public BodyBean getBody() { + return body; + } + + public void setBody(BodyBean body) { + this.body = body; + } + + public List getUpload() { + return upload; + } + + public void setUpload(List upload) { + this.upload = upload; + } + + public static class BodyBean { + /** + * pageNum : 0 + * list : [{"id":0,"name":"","address":"http://10.130.23.166:8080/cbt/img/blue.png","telephone":11,"geo":"标题11","price":"通过","type":"","dist":""}] + * total : 100 + * pageSize : 10 + * totalPage : 0 + */ + + private int pageNum; + private int total; + private int pageSize; + private int totalPage; + private List list; + + public int getPageNum() { + return pageNum; + } + + public void setPageNum(int pageNum) { + this.pageNum = pageNum; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getPageSize() { + return pageSize; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + public int getTotalPage() { + return totalPage; + } + + public void setTotalPage(int totalPage) { + this.totalPage = totalPage; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public static class ListBean { + /** + * id : 0 + * name : + * address : http://10.130.23.166:8080/cbt/img/blue.png + * telephone : 11 + * geo : 标题11 + * price : 通过 + * type : + * dist : + */ + + private int id; + private String name; + private String address; + private int telephone; + private String geo; + private String price; + private String type; + private String dist; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public int getTelephone() { + return telephone; + } + + public void setTelephone(int telephone) { + this.telephone = telephone; + } + + public String getGeo() { + return geo; + } + + public void setGeo(String geo) { + this.geo = geo; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDist() { + return dist; + } + + public void setDist(String dist) { + this.dist = dist; + } + + @Override + public String toString() { + return "ListBean{" + + "id=" + id + + ", name='" + name + '\'' + + ", address='" + address + '\'' + + ", telephone=" + telephone + + ", geo='" + geo + '\'' + + ", price='" + price + '\'' + + ", type='" + type + '\'' + + ", dist='" + dist + '\'' + + '}'; + } + } + + @Override + public String toString() { + return "BodyBean{" + + "pageNum=" + pageNum + + ", total=" + total + + ", pageSize=" + pageSize + + ", totalPage=" + totalPage + + ", list=" + list + + '}'; + } + } + + @Override + public String toString() { + return "JobSearchBean{" + + "status=" + status + + ", msg='" + msg + '\'' + + ", body=" + body + + ", upload=" + upload + + '}'; + } +} diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java index 784f971..eebc933 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java @@ -52,6 +52,7 @@ import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -72,7 +73,6 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC private EditText editDescribe, editNameContent; private Button btnSaveLocal; private PoiDatabase poiDatabase; - private String inode; private CheckBox checkBoxLife, checkBoxRight; private Spinner spinnerType, spinnerScutcheon, spinnerStake; String[] type = new String[]{"地上五层", "地上四层", "地上三层", "地上二层", "地上一层", "地下一层", "地下二层", "地下三层", "地下四层", "地下五层"}; @@ -88,6 +88,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC private CheckBox checkButton1, checkButton2, checkButton3, checkButton4, checkButton5, checkButton6; private int pid; private String station; + private LatLng latLng; public static ChargingPileFragment newInstance(Bundle bundle) { ChargingPileFragment fragment = new ChargingPileFragment(); @@ -381,7 +382,10 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } String p = chargingPileEntity.getP(); if (p != null) { - inode = p; + String[] split = p.split(","); + latLng = new LatLng(); + latLng.setLatitude(Double.parseDouble(split[0])); + latLng.setLongitude(Double.parseDouble(split[1])); } String memo = chargingPileEntity.getMemo(); if (memo != null) { @@ -516,8 +520,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC @Subscribe public void onEvent(Message data) { if (data.what == Constant.CHARGING_PILE_WORD) { - inode = data.obj.toString(); - Toast.makeText(getContext(), inode, Toast.LENGTH_SHORT).show(); + latLng = (LatLng) data.obj; } } @@ -535,11 +538,11 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC //保存数据库: ChargingPileEntity chargingPileEntity = new ChargingPileEntity(); ArrayList photoBean = new ArrayList<>(); - if (inode == null || inode.equals("")) { + if (latLng == null || latLng.equals("")) { Toast.makeText(getActivity(), "请确定点位", Toast.LENGTH_SHORT).show(); return; } else { - chargingPileEntity.setP(inode); + chargingPileEntity.setP(latLng.latitude+","+latLng.longitude); } String name = editNameContent.getText().toString().trim();//名称 if (name == null || name.equals("")) { @@ -736,8 +739,8 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC //根据要保存的数据的类型,调用对应的put方法, ChargingPileEntity chargingPileEntity = new ChargingPileEntity(); ArrayList photo = new ArrayList<>(); - if (inode != null) { - chargingPileEntity.setP(inode); + if (latLng != null) { + chargingPileEntity.setP(latLng.latitude+","+latLng.longitude); } String name = editNameContent.getText().toString().trim();//名称 if (name != null ||!name.equals("")) { diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java index e07d4d3..259d9e2 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java @@ -52,6 +52,7 @@ import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.PhotoPathUtil; import com.sothree.slidinguppanel.SlidingUpPanelLayout; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -84,10 +85,9 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. private Button btnUploading; private PoiDatabase poiDatabase; private PoiDao poiDao; - private String inode; private CheckBox checkBoxLife; private CheckBox checkBoxRight; - private String phone=null; + private String phone = null; private Spinner spinnerType; String[] ctype = new String[]{"全部", "poi", "道路", "充电站", "其他"}; private ArrayAdapter adapter; @@ -98,6 +98,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. private boolean aBoolean = false; private PoiEntity showPoiEntity; private ChargingPileDao chargingPileDao; + private LatLng latLng; public static ChargingStationFragment newInstance(Bundle bundle) { ChargingStationFragment fragment = new ChargingStationFragment(); @@ -228,8 +229,10 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. break; } } + @Override - public void onNothingSelected(AdapterView parent) {} + public void onNothingSelected(AdapterView parent) { + } }); //添加桩 linearChargingPile = findViewById(R.id.linear_charging_pile); @@ -316,7 +319,9 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. String x = showPoiEntity.getX(); String y = showPoiEntity.getY(); if (x != null && y != null) { - inode = x + "," + y; + latLng = new LatLng(); + latLng.setLatitude(Double.parseDouble(y)); + latLng.setLongitude(Double.parseDouble(x)); } String describe = showPoiEntity.getDescribe();//任务描述 if (describe != null) { @@ -381,7 +386,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. //根据保存时所用的name属性,获取SharedPreferences对象 SharedPreferences dataFile = getActivity().getSharedPreferences(Constant.DATA_FILE, 0); String pileFileString = dataFile.getString("chargingPileEntity", null); - if (pileFileString!=null){ + if (pileFileString != null) { ChargingPileEntity chargingPileEntity = new Gson().fromJson(pileFileString, ChargingPileEntity.class); Message obtains = Message.obtain(); obtains.what = Constant.CHARGING_STATION_PILE; @@ -410,6 +415,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. //提交新值。必须执行,否则前面的操作都无效。 edit.commit(); } + //禁用所有可操作性控件 private void disables() { checkBoxLife.setEnabled(false); @@ -438,8 +444,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. @Subscribe public void onEvent(Message data) { if (data.what == Constant.CHARGING_STATION_WORD) { - inode = data.obj.toString(); - Toast.makeText(getContext(), inode, Toast.LENGTH_SHORT).show(); + latLng = (LatLng) data.obj; } else if (data.what == Constant.CHARGING_PILE_STATION) { ChargingPileEntity chargingPileEntity = (ChargingPileEntity) data.obj; ArrayList chargingPileEntities = new ArrayList<>(); @@ -477,13 +482,12 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. } else { poiEntity.setAddress(site); } - if (inode == null || inode.equals("")) { + if (latLng == null) { Toast.makeText(getActivity(), "请确定点位", Toast.LENGTH_SHORT).show(); return; } else { - String[] split = inode.split(","); - poiEntity.setX(split[0]); - poiEntity.setY(split[1]); + poiEntity.setX(String.valueOf(latLng.longitude)); + poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editDescribe.getText().toString().trim(); if (describe == null || describe.equals("")) { @@ -521,7 +525,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. infoPhoto.add(new Info(tagInternal)); } String tagElse = (String) ivElse.getTag(); - if (tagElse == null ) { + if (tagElse == null) { Toast.makeText(getActivity(), "请拍照 设备编码", Toast.LENGTH_SHORT).show(); return; } else { @@ -557,7 +561,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. getActivity().runOnUiThread(new Runnable() { @Override public void run() { - poiEntity.setTaskId(allPoi.size()+1); + poiEntity.setTaskId(allPoi.size() + 1); } }); poiDao.insertPoiEntity(poiEntity); @@ -630,10 +634,9 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. if (site != null || !site.equals("")) { poiEntity.setAddress(site); } - if (inode != null) { - String[] split = inode.split(","); - poiEntity.setX(split[0]); - poiEntity.setY(split[1]); + if (latLng != null) { + poiEntity.setX(String.valueOf(latLng.longitude)); + poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editDescribe.getText().toString().trim(); if (describe != null || !describe.equals("")) { @@ -659,7 +662,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. infoPhoto.add(new Info(tagElse)); } String tagScutcheon = (String) ivScutcheon.getTag(); - if (tagScutcheon != null ) { + if (tagScutcheon != null) { infoPhoto.add(new Info(tagScutcheon)); } poiEntity.setPhotoInfo(infoPhoto); @@ -678,7 +681,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. getActivity().runOnUiThread(new Runnable() { @Override public void run() { - poiEntity.setTaskId(allPoi.size()+1); + poiEntity.setTaskId(allPoi.size() + 1); } }); } @@ -716,10 +719,9 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. if (site != null || !site.equals("")) { poiEntity.setAddress(site); } - if (inode != null) { - String[] split = inode.split(","); - poiEntity.setX(split[0]); - poiEntity.setY(split[1]); + if (latLng != null) { + poiEntity.setX(String.valueOf(latLng.longitude)); + poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editDescribe.getText().toString().trim(); if (describe != null || !describe.equals("")) { @@ -745,7 +747,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. infoPhoto.add(new Info(tagElse)); } String tagScutcheon = (String) ivScutcheon.getTag(); - if (tagScutcheon != null ) { + if (tagScutcheon != null) { infoPhoto.add(new Info(tagScutcheon)); } poiEntity.setPhotoInfo(infoPhoto); @@ -764,7 +766,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. getActivity().runOnUiThread(new Runnable() { @Override public void run() { - poiEntity.setTaskId(allPoi.size()+1); + poiEntity.setTaskId(allPoi.size() + 1); } }); } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java index 4150106..db36fa0 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java @@ -208,6 +208,7 @@ public class FilterFragment extends BaseDrawerFragment implements View.OnClickLi @Override public void onClick(String text, int index) { tvNumber.setText(text); + Constant.NUMBER=Integer.getInteger(text); } }); break; @@ -216,7 +217,7 @@ public class FilterFragment extends BaseDrawerFragment implements View.OnClickLi @Override public void onClick(String text, int index) { tvPhotograph.setText(text); - + Constant.PHOTOGRAPH=text; } }); break; @@ -225,6 +226,7 @@ public class FilterFragment extends BaseDrawerFragment implements View.OnClickLi @Override public void onClick(String text, int index) { tvExclusive.setText(text); + Constant.EXCLUSIVE=text; } }); break; @@ -233,6 +235,7 @@ public class FilterFragment extends BaseDrawerFragment implements View.OnClickLi @Override public void onClick(String text, int index) { tvType.setText(text); + Constant.TYPE=text; } }); } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java index bef4a86..ec5a6ba 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java @@ -43,6 +43,7 @@ import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -62,8 +63,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis private Spinner spinnerOther; - String[] others = new String[]{ "门牌", "道路施工", "标牌采集", "公交", "其他"}; - private String inode; + String[] others = new String[]{"门牌", "道路施工", "标牌采集", "公交", "其他"}; private EditText editTaskName, editOtherDescribe; private RelativeLayout rlPicture; private ImageView ivPicture; @@ -74,6 +74,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis private PoiDatabase poiDatabase; private PoiDao poiDao; private PoiEntity showPoiEntity; + private LatLng latLng; public static OtherFragment newInstance(Bundle bundle) { OtherFragment fragment = new OtherFragment(); @@ -195,8 +196,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis @Subscribe public void onEvent(Message data) { if (data.what == Constant.OTHER_WORD) { - inode = data.obj.toString(); - Toast.makeText(getContext(), inode, Toast.LENGTH_SHORT).show(); + latLng = (LatLng) data.obj; } } @@ -210,15 +210,20 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); if (showPoiEntity != null) { String name = showPoiEntity.getName();//名称 - if (name != null ) { - editTaskName.setText(name + ""); } + if (name != null) { + editTaskName.setText(name + ""); + } String x = showPoiEntity.getX(); String y = showPoiEntity.getY(); if (x != null && y != null) { - inode = x + "," + y; } + latLng = new LatLng(); + latLng.setLongitude(Double.parseDouble(x)); + latLng.setLatitude(Double.parseDouble(y)); + } String describe = showPoiEntity.getDescribe();//任务描述 if (describe != null) { - editOtherDescribe.setText(describe); } + editOtherDescribe.setText(describe); + } if (showPoiEntity.getPhotoInfo() != null) { for (int i = 0; i < showPoiEntity.getPhotoInfo().size(); i++) { String photo = showPoiEntity.getPhotoInfo().get(i).getPhoto(); @@ -268,13 +273,12 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis poiEntity.setName(name); } - if (inode == null || inode.equals("")) { + if (latLng == null) { Toast.makeText(getActivity(), "请确定点位", Toast.LENGTH_SHORT).show(); return; } else { - String[] split = inode.split(","); - poiEntity.setX(split[0]); - poiEntity.setY(split[1]); + poiEntity.setX(String.valueOf(latLng.longitude)); + poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editOtherDescribe.getText().toString().trim(); if (describe == null || describe.equals("")) { @@ -291,7 +295,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis infoList.add(new Info(tagPicture)); } String tagPictures = (String) ivPictures.getTag(); - if (tagPictures == null ) { + if (tagPictures == null) { Toast.makeText(getActivity(), "请 拍照", Toast.LENGTH_SHORT).show(); return; } else { @@ -353,10 +357,9 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis poiEntity.setName(name); } - if (inode != null) { - String[] split = inode.split(","); - poiEntity.setX(split[0]); - poiEntity.setY(split[1]); + if (latLng != null) { + poiEntity.setX(String.valueOf(latLng.longitude)); + poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editOtherDescribe.getText().toString().trim(); if (describe != null || !describe.equals("")) { @@ -367,7 +370,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis arrayList.add(new Info(tagPicture)); } String tagPictures = (String) ivPictures.getTag(); - if (tagPictures!= null) { + if (tagPictures != null) { arrayList.add(new Info(tagPictures)); } poiEntity.setPhotoInfo(arrayList); diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java index a151b00..4926728 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java @@ -46,6 +46,7 @@ import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -78,10 +79,10 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe private Button btnUploading; private PoiDatabase poiDatabase; private PoiDao poiDao; - private String inode; private CheckBox checkBoxLife; private CheckBox checkBoxRight; private PoiEntity showPoiEntity; + private LatLng latLng; public static PoiFragment newInstance(Bundle bundle) { PoiFragment fragment = new PoiFragment(); @@ -232,7 +233,9 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe String x = showPoiEntity.getX(); String y = showPoiEntity.getY(); if (x != null && y != null) { - inode = x + "," + y; + latLng = new LatLng(); + latLng.setLatitude(Double.parseDouble(y)); + latLng.setLongitude(Double.parseDouble(x)); } String describe = showPoiEntity.getDescribe();//任务描述 if (describe != null) { @@ -303,8 +306,7 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe @Subscribe public void onEvent(Message data) { if (data.what == Constant.POI_WORD) { - inode = data.obj.toString(); - Toast.makeText(getContext(), inode, Toast.LENGTH_SHORT).show(); + latLng = (LatLng) data.obj; } } @@ -336,13 +338,12 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe } else { poiEntity.setAddress(site); } - if (inode == null || inode.equals("")) { + if (latLng == null) { Toast.makeText(getActivity(), "请确定点位", Toast.LENGTH_SHORT).show(); return; } else { - String[] split = inode.split(","); - poiEntity.setX(split[0]); - poiEntity.setY(split[1]); + poiEntity.setX(String.valueOf(latLng.longitude)); + poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editDescribe.getText().toString().trim(); if (describe == null || describe.equals("")) { @@ -476,10 +477,9 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe if (site != null || !site.equals("")) { poiEntity.setAddress(site); } - if (inode!=null) { - String[] split = inode.split(","); - poiEntity.setX(split[0]); - poiEntity.setY(split[1]); + if (latLng != null) { + poiEntity.setX(String.valueOf(latLng.longitude)); + poiEntity.setY(String.valueOf(latLng.latitude)); } String describe = editDescribe.getText().toString().trim(); if (describe!= null || !describe.equals("")) { diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java index f5e0780..922c0d3 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Point; import android.location.Location; @@ -34,15 +35,23 @@ import com.kongzue.dialog.util.BaseDialog; import com.kongzue.dialog.util.DialogSettings; import com.kongzue.dialog.v3.MessageDialog; import com.kongzue.dialog.v3.ShareDialog; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.model.Response; import com.navinfo.outdoor.R; import com.navinfo.outdoor.activity.FragmentManagement; import com.navinfo.outdoor.api.Constant; import com.navinfo.outdoor.base.BaseDrawerFragment; import com.navinfo.outdoor.base.BaseFragment; +import com.navinfo.outdoor.bean.JobSearchBean; +import com.navinfo.outdoor.bean.NameAuthenticationBean; +import com.navinfo.outdoor.http.DialogCallback; +import com.navinfo.outdoor.http.HttpInterface; import com.navinfo.outdoor.room.ChargingPileEntity; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; +import com.navinfo.outdoor.util.Geohash; +import com.navinfo.outdoor.util.GeometryTools; import com.navinfo.outdoor.util.NetWorkUtils; import com.navinfo.outdoor.util.ToastUtil; import com.sothree.slidinguppanel.ScrollableViewHelper; @@ -55,15 +64,23 @@ import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; import com.tencent.tencentmap.mapsdk.maps.LocationSource; import com.tencent.tencentmap.mapsdk.maps.MapView; +import com.tencent.tencentmap.mapsdk.maps.Projection; import com.tencent.tencentmap.mapsdk.maps.TencentMap; import com.tencent.tencentmap.mapsdk.maps.UiSettings; +import com.tencent.tencentmap.mapsdk.maps.interfaces.Removable; import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds; import com.tencent.tencentmap.mapsdk.maps.model.Marker; import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions; import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle; +import com.tencent.tencentmap.mapsdk.maps.model.Polygon; +import com.tencent.tencentmap.mapsdk.maps.model.PolygonOptions; +import com.tencent.tencentmap.mapsdk.maps.model.Polyline; +import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions; +import com.vividsolutions.jts.geom.Geometry; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -100,6 +117,8 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen private ImageView ivMessage; private PoiDao poiDao; private ChargingPileEntity chargingPileEntity; + private String userEncode; + private String centerEncode; public static TreasureFragment newInstance(Bundle bundle) { TreasureFragment fragment = new TreasureFragment(); @@ -172,6 +191,93 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen //数据库 initThread(); + + } + + private void initList(TencentLocation tencentLocation) { + //获取中心点位置 + LatLng mapCenterPoint = getMapCenterPoint(); + ArrayList removables = new ArrayList<>(); + if (mapCenterPoint != null) { + centerEncode = Geohash.getInstance().encode(mapCenterPoint.latitude, mapCenterPoint.longitude); + } + + userEncode = Geohash.getInstance().encode(tencentLocation.getLatitude(),tencentLocation.getLongitude()); + + long date = System.currentTimeMillis(); + // 请求方式和请求url + OkGo.get(HttpInterface.TASK_LIST) + .tag(this) + // 请求的 tag, 主要用于取消对应的请求 + .params("userGeo", userEncode) + .params("centerGeo", centerEncode) + .params("date", date) + .params("pageSize", Constant.NUMBER) + .params("pageNum", "1") + .execute(new DialogCallback(JobSearchBean.class) { + @Override + public void onSuccess(Response response) { + Log.d("TAG", "onSuccess: " + response.body().toString() + "sssssssssssss"); + if (removables.size() > 0) { + for (int i = 0; i < removables.size(); i++) { + removables.get(i).remove(); + } + removables.clear(); + } + List list = response.body().getBody().getList(); + for (int i = 0; i < list.size(); i++) { + String geo = list.get(i).getGeo(); + Log.d("TAG", "onSuccess: " + geo); + Geometry geometry = GeometryTools.createGeometry(geo); + if ( geometry.getGeometryType().equals("Point")){//点 + LatLng latLng = GeometryTools.createLatLng(geo); + BitmapDescriptor custom = BitmapDescriptorFactory.fromResource(R.drawable.marker_road); + Marker marker = tencentMap.addMarker(new MarkerOptions(latLng)); + marker.setClickable(true); + removables.add(marker); + + }else if ( geometry.getGeometryType().equals("LineString")){//线 + List latLineString= GeometryTools.getLatLngs(geo); + // 构造 PolylineOpitons + PolylineOptions polylineOptions = new PolylineOptions() + .addAll(latLineString) + // 折线设置圆形线头 + .lineCap(true) + // 折线的颜色为绿色 + .color(0xff00ff00) + // 折线宽度为5像素 + .width(5) + // 还可以添加描边颜色 + .borderColor(0xffff0000) + // 描边颜色的宽度,线宽还是 25 像素,不过填充的部分宽度为 `width` - 2 * `borderWidth` + .borderWidth(1); + // 绘制折线 + Polyline polyline = tencentMap.addPolyline(polylineOptions); + removables.add(polyline); + }else if ( geometry.getGeometryType().equals("Polygon")){//面 + List latPolygon = GeometryTools.getLatLngs(geo); + Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). + //连接封闭图形的点 + addAll(latPolygon). + //填充颜色为红色 + fillColor(Color.parseColor("#97E0E7EC")). + //边线颜色为黑色 + strokeColor(0xff000000). + //边线宽度15像素 + strokeWidth(5)); + removables.add(polygon); + } + + } + } + + @Override + public void onError(Response response) { + super.onError(response); + Log.d("TAG", "onError: " + response.message()); + } + }); + } private void initThread() { @@ -183,7 +289,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen @Override public void run() { for (int i = 0; i < allPoi.size(); i++) { - LatLng position = new LatLng(Double.valueOf(allPoi.get(i).getX()), Double.valueOf(allPoi.get(i).getY())); + LatLng position = new LatLng(Double.valueOf(allPoi.get(i).getY()), Double.valueOf(allPoi.get(i).getX())); Marker marker = tencentMap.addMarker(new MarkerOptions(position)); marker.setClickable(true); PoiEntity poiEntity = allPoi.get(i); @@ -196,12 +302,12 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen setMainButtonVisiable(View.GONE); fragmentTransaction = supportFragmentManager.beginTransaction(); Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity",poiEntity); - bundle.putBoolean("boolean",false); + bundle.putSerializable("poiEntity", poiEntity); + bundle.putBoolean("boolean", false); gatherGetFragment = GatherGetFragment.newInstance(bundle); fragmentTransaction.replace(R.id.frame_layout, gatherGetFragment); fragmentTransaction.commit(); - Toast.makeText(getActivity(), marker.getId()+"", Toast.LENGTH_SHORT).show(); + Toast.makeText(getActivity(), marker.getId() + "", Toast.LENGTH_SHORT).show(); return false; } }); @@ -218,9 +324,9 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen SharedPreferences dataFile = getActivity().getSharedPreferences(Constant.DATA_FILE, 0); //根据数据类型,调用对应的get方法,通过键取得对应的值。 String dataFileString = dataFile.getString("poiEntity", null); - if (dataFileString!=null){ + if (dataFileString != null) { PoiEntity poiEntity = new Gson().fromJson(dataFileString, PoiEntity.class); - switch (poiEntity.getType()){ + switch (poiEntity.getType()) { case 0: DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; MessageDialog.show((AppCompatActivity) getContext(), "提示", "你poi页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { @@ -241,7 +347,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen @Override public boolean onClick(BaseDialog baseDialog, View v) { Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity",poiEntity); + bundle.putSerializable("poiEntity", poiEntity); RoadFragment roadFragment = RoadFragment.newInstance(bundle); showSlidingFragment(roadFragment); initRemovePoiSharePre(); @@ -255,7 +361,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen @Override public boolean onClick(BaseDialog baseDialog, View v) { Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity",poiEntity); + bundle.putSerializable("poiEntity", poiEntity); ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle); showSlidingFragment(chargingStationFragment); initRemovePoiSharePre(); @@ -269,7 +375,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen @Override public boolean onClick(BaseDialog baseDialog, View v) { Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity",poiEntity); + bundle.putSerializable("poiEntity", poiEntity); OtherFragment otherFragment = OtherFragment.newInstance(bundle); showSlidingFragment(otherFragment); initRemovePoiSharePre(); @@ -283,7 +389,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen @Override public boolean onClick(BaseDialog baseDialog, View v) { Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity",poiEntity); + bundle.putSerializable("poiEntity", poiEntity); PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle); showSlidingFragment(poiVideoFragment); initRemovePoiSharePre(); @@ -294,6 +400,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen } } } + public void initRemovePoiSharePre() { //获取SharedPreferences对象,方法中两个参数的意思为:第一个name //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 @@ -313,7 +420,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen public void onEvent(Message data) { if (data.what == Constant.FILTER_LIST_ITEM) { // 点击筛选的item PoiEntity poiEntity = (PoiEntity) data.obj; - LatLng position = new LatLng(Double.valueOf(poiEntity.getX()), Double.valueOf(poiEntity.getY())); + LatLng position = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); tencentMap.addMarker(new MarkerOptions(position)); sliding_layout.setPanelHeight(0); sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN); @@ -383,15 +490,15 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen frameLayout.setVisibility(View.GONE); sliding_layout.setPanelHeight(1000); sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); - }else { + } else { setMainButtonVisiable(View.VISIBLE); } } else if (data.what == Constant.CHARGING_STATION) {//充电站的充电桩 Bundle bundle = new Bundle(); bundle.putBoolean("isSliding", false); // 通知抽屉不收回 bundle.putString("station", (String) data.obj); - if (chargingPileEntity!=null){ - bundle.putSerializable("chargingPileEntity",chargingPileEntity); + if (chargingPileEntity != null) { + bundle.putSerializable("chargingPileEntity", chargingPileEntity); } ChargingPileFragment chargingPileFragment = ChargingPileFragment.newInstance(bundle); showSlidingFragment(chargingPileFragment); @@ -418,7 +525,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen sliding_layout.setPanelHeight(1000); sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); for (int i = 0; i < poiEntities.size(); i++) { - LatLng position = new LatLng(Double.valueOf(poiEntities.get(i).getX()), Double.valueOf(poiEntities.get(i).getY())); + LatLng position = new LatLng(Double.valueOf(poiEntities.get(i).getY()), Double.valueOf(poiEntities.get(i).getX())); tencentMap.addMarker(new MarkerOptions(position)); } } @@ -459,7 +566,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen Constant.markerLongitude = latLng.longitude; Message obtain = Message.obtain(); obtain.what = aInt; - obtain.obj = Constant.markerLatitude + "," + Constant.markerLongitude; + obtain.obj = latLng; EventBus.getDefault().post(obtain); } @@ -565,6 +672,9 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen CameraUpdate cameraUpdateOut = CameraUpdateFactory.zoomOut(); tencentMap.animateCamera(cameraUpdateOut); break; + case R.id.iv_refrish://刷新 + initList(Constant.currentLocation); + break; case R.id.iv_location://定位: if (Constant.currentLocation != null) { Constant.currentLocation.getLongitude(); @@ -706,6 +816,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen if (all) { //建立定位 initLocation(); + } else { Toast.makeText(getActivity(), "申请权限失败", Toast.LENGTH_SHORT).show(); } @@ -767,6 +878,9 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen location.setAccuracy(tencentLocation.getAccuracy()); locationChangedListener.onLocationChanged(location); locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER); + if (Constant.currentLocation == null) { + initList(tencentLocation); + } Constant.currentLocation = tencentLocation; Constant.markerCurrentLocation = tencentLocation; Constant.markerLatitude = tencentLocation.getLatitude(); @@ -786,4 +900,22 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen return true; } + /** + * 获取屏幕中心点位置 + * + * @return + */ + public LatLng getMapCenterPoint() { + int left = treasureMap.getLeft(); + int top = treasureMap.getTop(); + int right = treasureMap.getRight(); + int bottom = treasureMap.getBottom(); + // 获得屏幕点击的位置 + int x = (int) (treasureMap.getX() + (right - left) / 2); + int y = (int) (treasureMap.getY() + (bottom - top) / 2); + Projection projection = tencentMap.getProjection(); + LatLng pt = projection.fromScreenLocation(new Point(x, y)); + return pt; + } + } \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java b/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java index f315c2f..4e8857c 100644 --- a/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java +++ b/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java @@ -28,8 +28,14 @@ public class HttpInterface { public static final String USER_AUTH_ADD = IPm4 + "/userAuth/add"; //实名认证 //172.23.139.4:8001/m4/user/update - public static final String USER_UPDATE = IPm4+"/user/update";//用户资料 + public static final String USER_UPDATE = IPm4 + "/user/update";//用户资料 //172.23.139.4:8001/m4/userBankcard/update public static final String USER_BANKCARD_UP_DATA = IPm4 + "/userBankcard/update"; //绑定银行卡 + + + public static final String IPM3 = "http://172.23.139.4:8003/m4"; + + //172.23.139.4:8003/m4/task/1/getList + public static final String TASK_LIST = IPM3 + "/task/1/getList"; //任务搜索 } diff --git a/app/src/main/java/com/navinfo/outdoor/util/Geohash.java b/app/src/main/java/com/navinfo/outdoor/util/Geohash.java new file mode 100644 index 0000000..94dd9ca --- /dev/null +++ b/app/src/main/java/com/navinfo/outdoor/util/Geohash.java @@ -0,0 +1,153 @@ +package com.navinfo.outdoor.util; + +import java.util.BitSet; +import java.util.HashMap; + +public class Geohash { + + private Geohash(){} + + private static class GeohashInstance{ + private static final Geohash INSTANCE = new Geohash(); + } + + public static Geohash getInstance(){ + return GeohashInstance.INSTANCE; + } + + private static int numbits = 6 * 5; + /* + * final static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', + * '8', '9', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', + * 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; + */ + // 为了加密,所以改了base32编码代码表 + final static char[] digits = { 'd', 'f', 'g', 'y', 'n', 't', 'u', 'v', 'q', + 'b', '9', 's', 'z', '7', 'i', '2', 'h', '5', '0', 'p', '4', 'm', + '8', 'x', 'c', 'j', '6', 'e', '1', 'r', '3', 'k' }; + + final static HashMap lookup = new HashMap(); + static { + int i = 0; + for (char c : digits) + lookup.put(c, i++); + } + + public static void main(String[] args) { + String s = "1rn7exd5uhxy"; + System.out.println(s); + System.out.println(new Geohash().decode(s)[0]); + System.out.println(new Geohash().decode(s)[1]); + System.out.println(new Geohash().encode(40.073556024581194, 116.24643344432116)); + } + + //数据解密 + /** + * @param geohash 需要被解密的字符串 + * @return double[] 经纬度double数组,纬度(latitude)在前,经度在后(longitude) + * */ + public double[] decode(String geohash) { + try { + StringBuilder buffer = new StringBuilder(); + for (char c : geohash.toCharArray()) { + + int i = lookup.get(c) + 32; + buffer.append(Integer.toString(i, 2).substring(1)); + } + + long a = Long.parseLong(buffer.toString(), 2); + buffer.setLength(0); + buffer.append(Long.toBinaryString(a)); + + BitSet lonset = new BitSet(); + BitSet latset = new BitSet(); + + // even bits + int j = 0; + for (int i = 0; i < numbits * 2; i += 2) { + boolean isSet = false; + if (i < buffer.length()) + isSet = buffer.charAt(i) == '1'; + lonset.set(j++, isSet); + } + + // odd bits + j = 0; + for (int i = 1; i < numbits * 2; i += 2) { + boolean isSet = false; + if (i < buffer.length()) + isSet = buffer.charAt(i) == '1'; + latset.set(j++, isSet); + } + + double lon = decode(lonset, -180, 180); + double lat = decode(latset, -90, 90); + + return new double[] { lat, lon }; + } catch (RuntimeException re) { + re.printStackTrace(); + return null; + } + } + + private double decode(BitSet bs, double floor, double ceiling) { + double mid = 0; + for (int i = 0; i < bs.length(); i++) { + mid = (floor + ceiling) / 2; + if (bs.get(i)) + floor = mid; + else + ceiling = mid; + } + return mid; + } + +//数据加密 + /** + * @param lat,lon 需要被加密的double 值 + * */ + public String encode(double lat, double lon) { + BitSet latbits = getBits(lat, -90, 90); + BitSet lonbits = getBits(lon, -180, 180); + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < numbits; i++) { + buffer.append((lonbits.get(i)) ? '1' : '0'); + buffer.append((latbits.get(i)) ? '1' : '0'); + } + return base32(Long.parseLong(buffer.toString(), 2)); + } + + private BitSet getBits(double lat, double floor, double ceiling) { + BitSet buffer = new BitSet(numbits); + for (int i = 0; i < numbits; i++) { + double mid = (floor + ceiling) / 2; + if (lat >= mid) { + buffer.set(i); + floor = mid; + } else { + ceiling = mid; + } + } + return buffer; + } + + public static String base32(long i) { + char[] buf = new char[65]; + int charPos = 64; + boolean negative = (i < 0); + if (!negative) + i = -i; + while (i <= -32) { + buf[charPos--] = digits[(int) (-(i % 32))]; + i /= 32; + } + buf[charPos] = digits[(int) (-i)]; + + if (negative) + buf[--charPos] = '-'; + return new String(buf, charPos, (65 - charPos)); + } + + + +} diff --git a/app/src/main/java/com/navinfo/outdoor/util/GeometryTools.java b/app/src/main/java/com/navinfo/outdoor/util/GeometryTools.java new file mode 100644 index 0000000..cbc0e28 --- /dev/null +++ b/app/src/main/java/com/navinfo/outdoor/util/GeometryTools.java @@ -0,0 +1,1258 @@ +package com.navinfo.outdoor.util; + +import android.graphics.Point; +import android.util.Log; + +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.LineString; +import com.vividsolutions.jts.geom.MultiLineString; +import com.vividsolutions.jts.geom.MultiPoint; +import com.vividsolutions.jts.geom.MultiPolygon; +import com.vividsolutions.jts.geom.Polygon; +import com.vividsolutions.jts.io.WKTReader; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +/** + * @author qj 几何工具类 + */ +public class GeometryTools { + + static final double PI = 3.14159216; + private static volatile GeometryTools mInstance; + + public static String POINT_GEOMETRY_TYPE = "Point", LINE_GEOMETRY_TYPE = "LineString", POLYGON_GEOMETRY_TYPE = "Polygon"; + + public static GeometryTools getInstance() { + + if (mInstance == null) { + synchronized (GeometryTools.class) { + if (mInstance == null) { + mInstance = new GeometryTools(); + } + } + } + return mInstance; + } + + + /** + * 返回点几何 + * + * @param gp + * @return Geometry + */ + public static Geometry createGeometry(LatLng gp) { + if (gp != null) { + Coordinate coordinate = new Coordinate(gp.getLongitude(), gp.getLatitude()); + GeometryFactory factory = new GeometryFactory(); + Geometry geo = factory.createPoint(coordinate); + return geo; + } + + return null; + + } + + /** + * 返回点几何 + * + * @param gp + * @param formatDouble5 + * @return Geometry + */ + public static Geometry createGeometry(LatLng gp, boolean formatDouble5) { + if (gp != null) { + Coordinate coordinate = null; + if (formatDouble5) { + coordinate = new Coordinate(gp.getLongitude(), gp.getLatitude()); + } else { + coordinate = new Coordinate(gp.getLongitude(), gp.getLatitude()); + } + GeometryFactory factory = new GeometryFactory(); + Geometry geo = factory.createPoint(coordinate); + return geo; + } + + return null; + + } + + public static Geometry createGeometry(double[] coor) { + if (coor != null && coor.length == 2) { + Coordinate coordinate = new Coordinate(coor[0], coor[1]); + GeometryFactory factory = new GeometryFactory(); + Geometry geo = factory.createPoint(coordinate); + return geo; + } + + return null; + + } + + /** + * 获取多面 + * + * @param polygons + * @return + */ + public static MultiPolygon createMultiPolygon(Polygon[] polygons) { + if (polygons == null || polygons.length == 0) + return null; + MultiPolygon multiPolygon = null; + GeometryFactory factory = new GeometryFactory(); + + try { + + multiPolygon = factory.createMultiPolygon(polygons); + + } catch (Exception e) { + + } + + return multiPolygon; + } + + /** + * 获取多线 + * + * @param lineStrings + * @return + */ + public static MultiLineString createMultiLine(LineString[] lineStrings) { + if (lineStrings == null || lineStrings.length == 0) + return null; + MultiLineString multiLineString = null; + GeometryFactory factory = new GeometryFactory(); + + try { + + multiLineString = factory.createMultiLineString(lineStrings); + + } catch (Exception e) { + + } + + return multiLineString; + } + + /** + * 创建集合 + * + * @param coords [] + * @return Geometry + */ + public MultiPoint createMultiPoint(Coordinate[] coords) { + + if (coords == null || coords.length == 0) + return null; + + MultiPoint createMultiPoint = null; + + GeometryFactory factory = new GeometryFactory(); + + try { + + createMultiPoint = factory.createMultiPoint(coords); + + } catch (Exception e) { + + } + + return createMultiPoint; + } + + /** + * 创建集合 + * + * @param list [] + * @return Geometry + */ + public static MultiPoint createMultiPoint(List list) { + + if (list == null || list.size() == 0) + return null; + + MultiPoint createMultiPoint = null; + + GeometryFactory factory = new GeometryFactory(); + + try { + Coordinate[] coords = new Coordinate[list.size()]; + + for (int i = 0; i < list.size(); i++) { + coords[i] = new Coordinate(list.get(i).getLongitude(), list.get(i).getLatitude()); + } + + createMultiPoint = factory.createMultiPoint(coords); + + } catch (Exception e) { + + } + + return createMultiPoint; + } + + + /** + * 返回点几何 + * + * @param wkt + * @return Geometry + */ + public static Geometry createGeometry(String wkt) { + + if (wkt == null || wkt.equals("")) + return null; + + WKTReader reader = new WKTReader(); + + Geometry geometry; + try { + + geometry = reader.read(wkt); + + if (geometry != null) { + return geometry; + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + // BaseToast.makeText(context, "初始化任务失败!!!", Toast.LENGTH_SHORT).show(); + } + return null; + } + + /** + * 创建多边形几何 + * + * @param coords [] + * @return Geometry + */ + public static String createPolygon(Coordinate[] coords) { + GeometryFactory factory = new GeometryFactory(); + + Polygon gon = factory.createPolygon(coords); + + if (gon == null) + return null; + return gon.toString(); + } + + /** + * 创建多边形几何 + * + * @param LatLngList + * @return Polygon + */ + public static Polygon createPolygon(List LatLngList) { + if (LatLngList != null && LatLngList.size() >= 3) { + Coordinate[] coordinates = new Coordinate[LatLngList.size()]; + for (int i = 0; i < LatLngList.size(); i++) { + coordinates[i] = new Coordinate(LatLngList.get(i).getLongitude(), LatLngList.get(i).getLatitude()); + } + GeometryFactory factory = new GeometryFactory(); + return factory.createPolygon(coordinates); + } + return null; + } + + /* *//** + * 创建线 + * + * @param coords + * [] + * @return Geometry + * + * *//* + public String createLineString(Coordinate[] coords) { + LineString lineString = null; + GeometryFactory factory = new GeometryFactory(); + lineString = factory.createLineString(coords); + return lineString.toString(); + } +*/ + + /** + * 创建线 + * + * @param coords [] + * @return Geometry + */ + public LineString createLineString(Coordinate[] coords) { + LineString lineString = null; + GeometryFactory factory = new GeometryFactory(); + lineString = factory.createLineString(coords); + return lineString; + } + + /** + * 创建点 + * + * @param coord + * @return Point + */ + public com.vividsolutions.jts.geom.Point createPoint(Coordinate coord) { + com.vividsolutions.jts.geom.Point point = null; + GeometryFactory factory = new GeometryFactory(); + point = factory.createPoint(coord); + return point; + } + + + /** + * 点几何转换为LatLng + * + * @param geometry POINT (116.4087300000000056 39.9392050000000012) + * @return LatLng + */ + public static LatLng createLatLng(String geometry) { + + if (geometry == null || geometry.equals("")) + return null; + + WKTReader reader = new WKTReader(); + + Geometry geometrys; + + try { + + geometrys = reader.read(geometry); + + if (geometrys != null) { + + com.vividsolutions.jts.geom.Point point = geometrys + .getInteriorPoint(); + + LatLng geoInteriorPoint = new LatLng(point.getY(), point.getX()); + + if (geometrys.getGeometryType().equalsIgnoreCase("Point")) { + + Coordinate coordinate = geometrys.getCoordinate(); + + LatLng geo = new LatLng(coordinate.y, coordinate.x); + + return geo; + + } else if (geometrys.getGeometryType().equalsIgnoreCase("LineString") || geometrys.getGeometryType().equalsIgnoreCase("MultiLineString")) { + Coordinate[] coordinates = geometrys.getCoordinates(); + if (coordinates != null && coordinates.length > 0) { + LatLng geo = new LatLng(coordinates[0].y, coordinates[0].x); + return geo; + } else { + return geoInteriorPoint; + } + + } else { + + return geoInteriorPoint; + + } + + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + // BaseToast.makeText(context, "初始化任务失败!!!", Toast.LENGTH_SHORT).show(); + } + return null; + } + + /** + * 计算两点距离 + * + * @param startLatLng + * @param endLatLng + * @return double:单位 米 + */ + public static double distanceToDouble(LatLng startLatLng, LatLng endLatLng) { + if (startLatLng != null && endLatLng != null) { + Geometry startGeo = createGeometry(startLatLng); + Geometry endGeo = createGeometry(endLatLng); + double d = startGeo.distance(endGeo); + return d * 100000; + } + return 0; + + } + + public static LatLng getLineStringCenter(String lineString) { + List points = getLatLngs(lineString); + return getLineStringCenter(points); + } + + public static LatLng getLineStringCenter(List points) { + if (points != null && points.size() > 1) { + if (points.size() == 2) { + double x1 = points.get(0).getLongitude(); + double y1 = points.get(0).getLatitude(); + double x2 = points.get(1).getLongitude(); + double y2 = points.get(1).getLatitude(); + LatLng newPoint = new LatLng((y1 + y2) / 2, (x1 + x2) / 2); + return newPoint; + } else { + double total = 0; + ArrayList dList = new ArrayList(); + for (int i = 0; i < points.size() - 1; i++) { + double lt = total; + double dis = distanceToDouble(points.get(i), points.get(i + 1)); + dList.add(lt + dis); + total += dis; + } + Log.e("jingo", "line lengh =" + total); + total = total / 2; + for (int i = 0; i < dList.size(); i++) { + double a = dList.get(i); + double b = 0; + if (i > 0) { + b = dList.get(i - 1); + } + if (a > total) { + if (a - total < 4) { + return points.get(i); + } + double dx = (a - total) * 0.5 / (a - b); + LatLng point1 = points.get(i); + LatLng point2 = points.get(i + 1); + double x; + if (point1.getLongitude() < point2.getLongitude()) { + x = (point2.getLongitude() - point1.getLongitude()) * dx; + x = point2.getLongitude() - x; + } else { + x = (point1.getLongitude() - point2.getLongitude()) * dx; + x = point2.getLongitude() + x; + } + double y; + if (point1.getLatitude() > point2.getLatitude()) { + y = (point1.getLatitude() - point2.getLatitude()) * dx; + y = point2.getLatitude() + y; + } else { + y = (point2.getLatitude() - point1.getLatitude()) * dx; + y = point2.getLatitude() - y; + } + LatLng LatLng = new LatLng(y, x); + return LatLng; + } else { + if (total - a < 4) { + return points.get(i + 1); + } + } + } + } + } + return null; + } + + public static LatLng getLineStringCenter(List points, int[] index) { + if (points != null && points.size() > 1) { + if (points.size() == 2) { + double x1 = points.get(0).getLongitude(); + double y1 = points.get(0).getLatitude(); + double x2 = points.get(1).getLongitude(); + double y2 = points.get(1).getLatitude(); + LatLng newPoint = new LatLng((y1 + y2) / 2, (x1 + x2) / 2); + if (index != null && index.length > 1) { + index[0] = 0; + index[1] = 1; + } + return newPoint; + } else { + double total = 0; + ArrayList dList = new ArrayList(); + for (int i = 0; i < points.size() - 1; i++) { + double lt = total; + double dis = distance(points.get(i).toString(), points.get(i + 1).toString()); + dList.add(lt + dis); + total += dis; + } + Log.e("jingo", "line lengh =" + total); + total = total / 2; + for (int i = 0; i < dList.size(); i++) { + double a = dList.get(i); + double b = 0; + if (i > 0) { + b = dList.get(i - 1); + } + if (a > total) { + if (a - total < 4) { + if (index != null && index.length > 1) { + index[0] = i; + index[1] = i + 1; + } + return points.get(i); + } + double dx = (a - total) * 0.5 / (a - b); + LatLng point1 = points.get(i); + LatLng point2 = points.get(i + 1); + double x; + if (point1.getLongitude() < point2.getLongitude()) { + x = (point2.getLongitude() - point1.getLongitude()) * dx; + x = point2.getLongitude() - x; + } else { + x = (point1.getLongitude() - point2.getLongitude()) * dx; + x = point2.getLongitude() + x; + } + double y; + if (point1.getLatitude() > point2.getLatitude()) { + y = (point1.getLatitude() - point2.getLatitude()) * dx; + y = point2.getLatitude() + y; + } else { + y = (point2.getLatitude() - point1.getLatitude()) * dx; + y = point2.getLatitude() - y; + } + LatLng LatLng = new LatLng(y, x); + if (index != null && index.length > 1) { + index[0] = i; + index[1] = i + 1; + } + return LatLng; + } else { + if (total - a < 4) { + if (index != null && index.length > 1) { + index[0] = i; + index[1] = i + 1; + } + return points.get(i + 1); + } + } + } + } + } + return null; + } + + /** + * LINESTRING (116.4206899999999933 39.9620999999999995, + * 116.4184900000000056 39.9620600000000010) + * + * @param str + * @return + */ + public static List getLatLngs(String str) { + if (isEmpty(str)) + return null; + List list = null; + Geometry geometry = createGeometry(str); + if (geometry != null) { + Coordinate[] coordinates = geometry.getCoordinates(); + if (coordinates != null && coordinates.length > 0) { + list = new ArrayList(); + for (Coordinate coor : coordinates) { + list.add(new LatLng(coor.y, coor.x)); + } + } + } + return list; + } + + public static Coordinate[] getLatLngs2(String str) { + Coordinate[] coordinates = null; + if (str == null || str.trim().equals("")) + return coordinates; + Geometry geometry = createGeometry(str); + if (geometry != null) { + coordinates = geometry.getCoordinates(); + } + return coordinates; + } + + public static String getLineString(List list) { + + if (list != null && list.size() > 1) { + int size = list.size(); + Coordinate[] coors = new Coordinate[size]; + for (int i = 0; i < size; i++) { + LatLng gp = list.get(i); + coors[i] = new Coordinate(gp.getLongitude(), gp.getLatitude()); + } + GeometryFactory factory = new GeometryFactory(); + Geometry geo = factory.createLineString(coors); + if (geo != null) + return geo.toString(); + } + return null; + } + + public static String getLineStringNoDouble5(List list) { + + if (list != null && list.size() > 1) { + int size = list.size(); + Coordinate[] coors = new Coordinate[size]; + for (int i = 0; i < size; i++) { + LatLng gp = list.get(i); + coors[i] = new Coordinate(gp.getLongitude(), gp.getLatitude()); + } + GeometryFactory factory = new GeometryFactory(); + Geometry geo = factory.createLineString(coors); + if (geo != null) + return geo.toString(); + } + return null; + } + + /** + * 获取线型 + * + * @param list + * @return + */ + public static LineString getLineStrinGeo(List list) { + + if (list != null && list.size() > 1) { + int size = list.size(); + Coordinate[] coors = new Coordinate[size]; + for (int i = 0; i < size; i++) { + LatLng gp = list.get(i); + coors[i] = new Coordinate(gp.getLongitude(), gp.getLatitude()); + } + return getLineStrinGeo(coors); + } + return null; + } + + /** + * 获取线型 + * + * @param coors + * @return + */ + public static LineString getLineStrinGeo(Coordinate[] coors) { + + if (coors != null && coors.length > 1) { + GeometryFactory factory = new GeometryFactory(); + LineString geo = factory.createLineString(coors); + if (geo != null) + return geo; + } + return null; + } + + /** + * 获取线型的外扩矩形 + * + * @param list + * @return + */ + public static Polygon getPolygonEnvelope(List list) { + LineString lineString = getLineStrinGeo(list); + if (lineString != null) { + Geometry geometry = lineString.getEnvelope(); + if (geometry != null && geometry.getGeometryType().equals("Polygon")) { + return (Polygon) geometry; + } + } + return null; + + } + + public static String getPolygonString(List list) { + if (list != null && list.size() > 2) { + LatLng frist = list.get(0); + LatLng last = list.get(list.size() - 1); + if (frist.getLongitude() != last.getLongitude() || frist.getLatitude() != last.getLatitude()) { + return null; + } + Coordinate[] coors = new Coordinate[list.size()]; + + for (int i = 0; i < list.size(); i++) { + LatLng gp = list.get(i); + coors[i] = new Coordinate(gp.getLongitude(), gp.getLatitude()); + } + GeometryFactory factory = new GeometryFactory(); + Geometry geo = factory.createPolygon(coors); + if (geo != null) + return geo.toString(); + } + + return null; + + } + + public static String getMultiLineString(List> list) { + if (list != null && !list.isEmpty()) { + StringBuffer result = new StringBuffer(); + result.append("MULTILINESTRING("); + for (int i = 0; i < list.size(); ++i) { + List pointList = list.get(i); + if (pointList != null && !pointList.isEmpty()) { + result.append("("); + for (int j = 0; j < pointList.size(); ++j) { + result.append(pointList.get(j).getLongitude()); + result.append(" "); + result.append(pointList.get(j).getLatitude()); + if (j == pointList.size() - 1) { + result.append(")"); + } else { + result.append(","); + } + } + if (i != list.size() - 1) { + result.append(","); + } + } + } + result.append(")"); + return result.toString(); + } + return null; + } + + public static List> getLatLngArrFromMultiLineString(String multiLintString) { + if (isEmpty(multiLintString)) + return null; + multiLintString = multiLintString.substring(multiLintString.indexOf("(") + 1, + multiLintString.length() - 1); + if (!isEmpty(multiLintString)) { + List> resultList = new ArrayList>(); + while (!isEmpty(multiLintString)) { + int startIndex = multiLintString.indexOf("("); + int endIndex = multiLintString.indexOf(")"); + if (startIndex < endIndex) { + endIndex++; + String geometry = multiLintString.substring(startIndex, endIndex); + if (isEmpty(geometry)) + continue; + if (geometry.startsWith("(")) { + geometry = geometry.substring(1, geometry.length()); + } + if (geometry.endsWith(")")) { + geometry = geometry.substring(0, geometry.length() - 1); + } + String points[] = geometry.split(","); + List list = new ArrayList(); + for (int i = 0; i < points.length; i++) { + String point[] = points[i].trim().split(" "); + if (point.length == 2) { + list.add(new LatLng(Double.parseDouble(point[1].trim()), + Double.parseDouble(point[0].trim()))); + } + } + if (list != null && !list.isEmpty()) { + resultList.add(list); + } + multiLintString = multiLintString.substring(endIndex); + } + } + if (resultList != null && !resultList.isEmpty()) { + return resultList; + } + } + + return null; + } + + + public Geometry focalPoint(Geometry geo1, Geometry geo2) { + if (geo1 == null || geo2 == null) + return null; + + Geometry geo = geo1.intersection(geo2); + Log.i("geo", geo.toString() + "===1"); + geo = geo1.union(geo2); + Log.i("geo", geo.toString() + "===2"); + geo = geo1.symDifference(geo2); + Log.i("geo", geo.toString() + "===3"); + return null; + } + + /** + * 角度变换 + * + * @param angle + * @return angle; + */ + public double angleSwap(double angle) { + + if (angle >= 180) + angle = angle - 180; + else + angle = angle + 180; + angle = formatDouble5(angle); + return angle; + } + + /** + * 是否第一个点 + * + * @param lineString + * @param point + * @return boolean; + */ + public boolean isFirstPoint(String lineString, String point) { + if (isEmpty(lineString) || isEmpty(point)) + return false; + + Geometry lineGeo = createGeometry(lineString); + + Geometry pGeo = createGeometry(point); + + if (lineGeo != null && lineGeo.getGeometryType().equals("LineString") && pGeo != null && pGeo.getGeometryType().equals("Point")) { + Coordinate[] coords = lineGeo.getCoordinates(); + if (coords.length > 0) { + if (coords[0].x == pGeo.getCoordinate().x && coords[0].y == pGeo.getCoordinate().y) + return true; + } + } + + return false; + } + + /** + * 是否最后点 + * + * @param lineString + * @param point + * @return boolean; + */ + public boolean isEndPoint(String lineString, String point) { + + if (isEmpty(lineString) || isEmpty(point)) + return false; + + Geometry lineGeo = createGeometry(lineString); + + Geometry pGeo = createGeometry(point); + + if (lineGeo != null && lineGeo.getGeometryType().equals("LineString") && pGeo != null && pGeo.getGeometryType().equals("Point")) { + Coordinate[] coords = lineGeo.getCoordinates(); + if (coords.length > 0) { + if (coords[coords.length - 1].x == pGeo.getCoordinate().x && coords[coords.length - 1].y == pGeo.getCoordinate().y) + return true; + } + } + + return false; + + } + + /** + * 是否起点或终点 + * + * @param lineString + * @param point + * @return boolean; + */ + public boolean isFirstOrEndPoint(String lineString, String point) { + + + if (isEmpty(lineString) ||isEmpty(point)) + return false; + + Geometry lineGeo = createGeometry(lineString); + + Geometry pGeo = createGeometry(point); + + if (lineGeo != null && lineGeo.getGeometryType().equals("LineString") && pGeo != null && pGeo.getGeometryType().equals("Point")) { + Coordinate[] coords = lineGeo.getCoordinates(); + if (coords.length > 0) { + + if (coords[coords.length - 1].x == pGeo.getCoordinate().x && coords[coords.length - 1].y == pGeo.getCoordinate().y) + return true; + + if (coords[coords.length - 1].x == pGeo.getCoordinate().x && coords[coords.length - 1].y == pGeo.getCoordinate().y) + return true; + } + } + + return false; + + } + + /** + * 判断捕捉集合中是否包含传入的点位信息 + * + * @param geoList + * @return int; + */ + public int isListContain(List geoList, LatLng mLatLng) { + + if (geoList != null && geoList.size() > 0 && mLatLng != null) { + for (int i = 0; i < geoList.size(); i++) { + if (geoList.get(i).equals(mLatLng)) { + return i; + } + } + } + + return -1; + } + + + public int LocatePointInPath(List list, LatLng point) { + int index = -1; + + if (list == null || list.size() < 2 || point == null) { + return index; + } +// createPolygon(getEnvelope(new LatLng(formatDouble5(point.getLongitude()), formatDouble5(point.getLatitude())), 6, 2)) + Geometry geomerty = createGeometry(point); + + Coordinate[] coods = new Coordinate[2]; + HashMap distance = new HashMap(); + //遍历线节点,判断垂足在哪个线段上,并将垂足插入 + for (int i = 0; i < list.size(); i++) { + if (i != list.size() - 1) { + + coods[0] = new Coordinate(list.get(i).getLongitude(), list.get(i).getLatitude()); + + coods[1] = new Coordinate(list.get(i + 1).getLongitude(), list.get(i + 1).getLatitude()); + + LineString line = createLineString(coods); + + double dou = line.distance(geomerty); + distance.put(i, dou); + } + } + double temp = distance.get(0); + for (int i = 1; i < distance.size(); i++) { + if (temp > distance.get(i)) { + temp = distance.get(i); + } + } + for (int i = 0; i < distance.size(); i++) { + if (temp == distance.get(i)) { + return i; + } + } + return index; + } + + + //是否是相交面 + public static boolean isSimplePolygon(List list) { + + if (list != null && list.size() > 0) { + Geometry polygon = createGeometry(getPolygonString(list)); + if (polygon != null) { + return polygon.isSimple(); + } + } + + return false; + } + + public static boolean isSimplePolygon(List list, Point endPoint) { + + if (list != null && list.size() > 0) { + + if (list != null && list.size() > 2) { + Point frist = list.get(0); + Point last = list.get(list.size() - 1); + if (frist.x != last.x || frist.y != last.y) { + return false; + } + int size = list.size(); + if (endPoint != null) { + size++; + } + Coordinate[] coors = new Coordinate[size]; + + for (int i = 0; i < list.size(); i++) { + Point gp = list.get(i); + coors[i] = new Coordinate(gp.x, gp.y); + } + if (endPoint != null) { + coors[coors.length - 1] = coors[coors.length - 2]; + coors[coors.length - 2] = new Coordinate(endPoint.x, endPoint.y); + } + GeometryFactory factory = new GeometryFactory(); + Geometry geo = factory.createPolygon(coors); + if (geo != null) { + return geo.isSimple(); + } + } + } + + return false; + } + + /** + * 小数点后四舍五入 精确到第5位 + * + * @param d + * @return + */ + private double formatDouble5(double d) { + BigDecimal bg = new BigDecimal(d); + double f1 = bg.setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue(); + return f1; + } + + /** + * 是否包含点 + * + * @param //List wkts + * @param //LatLng LatLng + * @return int + */ + public int isContainsGeo(List wkts, LatLng LatLng) { + + if (wkts == null || wkts.size() == 0 || LatLng == null) { + return -1; + } + + com.vividsolutions.jts.geom.Point point = createPoint(new Coordinate(LatLng.getLongitude(), LatLng.getLatitude())); + + for (int i = 0; i < wkts.size(); i++) { + + Geometry geometry = createGeometry(wkts.get(i)); + + if (geometry != null && geometry.getGeometryType().equals("Polygon")) { + + Polygon polygon = (Polygon) geometry; + + + boolean result = geometry.contains(point); + + if (result) + return i; + } + } + + return -1; + } + + + public static List getLineIntersectionLatLng(LineString lineString) { + if (lineString != null) { + + Coordinate[] coords = lineString.getCoordinates(); + + List list = new ArrayList(); + + GeometryFactory factory = new GeometryFactory(); + + for (int i = 0; i < coords.length; i++) { + if (i != coords.length - 1) { + Coordinate[] coord = new Coordinate[2]; + coord[0] = coords[i]; + coord[1] = coords[i + 1]; + LineString line = factory.createLineString(coord); + if (line != null) + list.add(line); + } + } + + List listLatLng = new ArrayList(); + + if (list != null && list.size() > 0) { + + for (int i = 0; i < list.size(); i++) { + LineString line1 = list.get(i); + + for (int j = 0; j < list.size(); j++) { + if (i != j) { + LineString line2 = list.get(j); + Geometry geometry = line1.intersection(line2); + if (geometry != null && !geometry.isEmpty() && geometry.getGeometryType().equalsIgnoreCase("Point")) { + if (!line2.getStartPoint().equals(geometry) && !line2.getEndPoint().equals(geometry)) { + listLatLng.add(new LatLng(geometry.getCoordinate().y, geometry.getCoordinate().x)); + } + } + } + } + + } + + } + if (listLatLng != null && listLatLng.size() > 0) { + return listLatLng; + } + } + return null; + } + + /** + * 点与几何最近点位置 + * + * @param list + * @param LatLng + * @return LatLng + * @author qiji + */ + public static LatLng getZuijinLatLng(List list, LatLng LatLng) {//MapManager.getInstance().getMap().getMapCenterGeoLocation()屏幕中心点 + + if (list == null || list.size() == 0 || LatLng == null) + return null; + + double dis = 0; + + LatLng geo = null; + + for (LatLng latLng : list) { + + double disTemp = distanceToDouble(latLng, latLng); + + if (dis == 0 || dis < disTemp) { + + dis = disTemp; + + geo = LatLng; + + } + + } + + return geo; + } + + public static String GeometryFormatDouble5(String geometry) { + try { + + LatLng point = createLatLng(geometry); + + return createGeometry(point).toString(); + } catch (Exception e) { + + } + + return ""; + } + + + public static double distance(String geo1, String geo2) { + if (isEmpty(geo1)||isEmpty(geo2)) { + return -1; + } + Geometry mGeo = createGeometry(geo1); + + Geometry mGeo2 = createGeometry(geo2); + + if (mGeo != null && mGeo2 != null) { + + return mGeo.distance(mGeo2); + } + return -1; + } + + + public enum SNAP_TYPE { + SNAP_PIXEL, SNAP_METER; + } + + + //经纬度转墨卡托 + public static LatLng lonLat2Mercator(LatLng lonLat) { + + double x = lonLat.getLongitude() * 20037508.34 / 180; + double y = Math.log(Math.tan((90 + lonLat.getLatitude()) * Math.PI / 360)) / (Math.PI / 180); + y = y * 20037508.34 / 180; + LatLng mercator = new LatLng(y, x); + return mercator; + } + + //墨卡托转经纬度 + public static LatLng Mercator2lonLat(LatLng mercator) { + + double x = mercator.getLongitude() / 20037508.34 * 180; + double y = mercator.getLatitude() / 20037508.34 * 180; + y = 180 / Math.PI * (2 * Math.atan(Math.exp(y * Math.PI / 180)) - Math.PI / 2); + LatLng lonLat = new LatLng(y, x); + return lonLat; + } + + public static boolean isCheckError(double lon, double lat) { +/* if(lon==0&&lat==0){ + return true; + }*/ + + if (lon > 180 || lon < -180 || lat > 90 || lat < -90) { + return true; + } + return false; + } + + + /** + * @param isFormatDouble5 是否只保留小数点后5位 + * @return + */ + public static Geometry getPolygonGeometry(List mArrLatLng, boolean isFormatDouble5) { + if (mArrLatLng != null && mArrLatLng.size() > 0) { + + if (mArrLatLng != null && mArrLatLng.size() > 0) { + Coordinate[] coordinates = new Coordinate[mArrLatLng.size()]; + for (int i = 0; i < mArrLatLng.size(); i++) { + Coordinate coordinate = null; + if (isFormatDouble5) + coordinate = new Coordinate(mArrLatLng.get(i).getLongitude(), mArrLatLng.get(i).getLatitude()); + else + coordinate = new Coordinate(mArrLatLng.get(i).getLongitude(), mArrLatLng.get(i).getLatitude()); + coordinates[i] = coordinate; + } + return getPolygonGeometry(coordinates); + } + + } + return null; + } + + /** + * @return + */ + public static Geometry getPolygonGeometry(Coordinate[] coordinates) { + if (coordinates!=null&&coordinates.length>0) { + GeometryFactory factory = new GeometryFactory(); + Polygon polygon = factory.createPolygon(coordinates); + if (polygon != null) + return polygon; + } + return null; + } + +// public static String getGeoJsonStr(Geometry geometry) throws ParseException { +// GeoJSON geoJSONObject = geoJsonWriter.write(wktReader.read(geometry.toString())); +// return geoJSONObject.toString(); +// } + + +// /** +// * 经纬度转WEB墨卡托 +// * @param geom +// * @return +// */ +// public static Geometry lonlat2WebMactor(Geometry geom){ +// try{ +// //这里是以OGC WKT形式定义的是World Mercator投影,网页地图一般使用该投影 +// //CoordinateReferenceSystem crsTarget = CRS.parseWKT(strWKTMercator); +//// CoordinateReferenceSystem crsTarget = CRS.decode("EPSG:3857"); +// // 这里是以OGC WKT形式定义的是World Mercator投影,网页地图一般使用该投影 +// final String strWKTMercator = "PROJCS[\"World_Mercator\"," +// + "GEOGCS[\"GCS_WGS_1984\"," +// + "DATUM[\"WGS_1984\"," +// + "SPHEROID[\"WGS_1984\",6378137,298.257223563]]," +// + "PRIMEM[\"Greenwich\",0]," +// + "UNIT[\"Degree\",0.017453292519943295]]," +// + "PROJECTION[\"Mercator_1SP\"]," +// + "PARAMETER[\"False_Easting\",0]," +// + "PARAMETER[\"False_Northing\",0]," +// + "PARAMETER[\"Central_Meridian\",0]," +// + "PARAMETER[\"latitude_of_origin\",0]," +// + "UNIT[\"Meter\",1]]"; +// CoordinateReferenceSystem mercatroCRS = CRS.parseWKT(strWKTMercator); +// +// // 投影转换 +// MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mercatroCRS); +// return JTS.transform(geom, transform); +// } +// catch (Exception e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// return null; +// } +// } + + private static boolean isEmpty(String str) { + return str == null || str.trim().equals(""); + } +} diff --git a/app/src/main/res/drawable/marker_charge_bg.png b/app/src/main/res/drawable/marker_charge_bg.png new file mode 100644 index 0000000..04db664 Binary files /dev/null and b/app/src/main/res/drawable/marker_charge_bg.png differ diff --git a/app/src/main/res/drawable/marker_other_bg.png b/app/src/main/res/drawable/marker_other_bg.png new file mode 100644 index 0000000..808c975 Binary files /dev/null and b/app/src/main/res/drawable/marker_other_bg.png differ diff --git a/app/src/main/res/drawable/marker_poi_bg.png b/app/src/main/res/drawable/marker_poi_bg.png new file mode 100644 index 0000000..733e0e6 Binary files /dev/null and b/app/src/main/res/drawable/marker_poi_bg.png differ diff --git a/app/src/main/res/drawable/marker_road.png b/app/src/main/res/drawable/marker_road.png new file mode 100644 index 0000000..26e7ff1 Binary files /dev/null and b/app/src/main/res/drawable/marker_road.png differ diff --git a/app/src/main/res/drawable/marker_road_bg.png b/app/src/main/res/drawable/marker_road_bg.png new file mode 100644 index 0000000..a0efacb Binary files /dev/null and b/app/src/main/res/drawable/marker_road_bg.png differ diff --git a/app/src/main/res/layout/loading.xml b/app/src/main/res/layout/loading.xml new file mode 100644 index 0000000..82ff298 --- /dev/null +++ b/app/src/main/res/layout/loading.xml @@ -0,0 +1,31 @@ + + + + + + + \ No newline at end of file