|
@@ -32,6 +32,7 @@ import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
import com.xzjmyk.pm.activity.util.BaiduMapUtil;
|
|
import com.xzjmyk.pm.activity.util.BaiduMapUtil;
|
|
|
|
|
|
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
@@ -47,6 +48,7 @@ import java.util.List;
|
|
|
* 1、title(标题String) 2、style(主题 int)
|
|
* 1、title(标题String) 2、style(主题 int)
|
|
|
* 3、latlng(对比距离的位置) l 4、search(是否有搜索框 boolean)
|
|
* 3、latlng(对比距离的位置) l 4、search(是否有搜索框 boolean)
|
|
|
* 5、resultCode(返回码 int) 6、resultName(返回key String )
|
|
* 5、resultCode(返回码 int) 6、resultName(返回key String )
|
|
|
|
|
+ * 6、isKm(是否使用km距离计算 boolean)
|
|
|
*/
|
|
*/
|
|
|
public class LocationSearchActivity extends BaseActivity {
|
|
public class LocationSearchActivity extends BaseActivity {
|
|
|
@ViewInject(R.id.search_edit)
|
|
@ViewInject(R.id.search_edit)
|
|
@@ -65,6 +67,7 @@ public class LocationSearchActivity extends BaseActivity {
|
|
|
private String resultName = "resultName";//返回的参数名称
|
|
private String resultName = "resultName";//返回的参数名称
|
|
|
private String keyWork;//返回的参数名称
|
|
private String keyWork;//返回的参数名称
|
|
|
private int radius = 1000;
|
|
private int radius = 1000;
|
|
|
|
|
+ private boolean isKm = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<PoiInfo> listData; //周围地址主体;列表
|
|
private List<PoiInfo> listData; //周围地址主体;列表
|
|
@@ -118,6 +121,7 @@ public class LocationSearchActivity extends BaseActivity {
|
|
|
if (!StringUtils.isEmpty(title))
|
|
if (!StringUtils.isEmpty(title))
|
|
|
getSupportActionBar().setTitle(title);
|
|
getSupportActionBar().setTitle(title);
|
|
|
single = intent.getBooleanExtra("single", true);
|
|
single = intent.getBooleanExtra("single", true);
|
|
|
|
|
+ isKm = intent.getBooleanExtra("isKm", false);
|
|
|
search = intent.getBooleanExtra("search", false);
|
|
search = intent.getBooleanExtra("search", false);
|
|
|
resultCode = intent.getIntExtra("resultCode", 0x20);
|
|
resultCode = intent.getIntExtra("resultCode", 0x20);
|
|
|
resultName = intent.getStringExtra("resultName");
|
|
resultName = intent.getStringExtra("resultName");
|
|
@@ -164,7 +168,6 @@ public class LocationSearchActivity extends BaseActivity {
|
|
|
loadDataByNeer();
|
|
loadDataByNeer();
|
|
|
} else
|
|
} else
|
|
|
loadDataByCity();
|
|
loadDataByCity();
|
|
|
-
|
|
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|
|
@@ -177,11 +180,14 @@ public class LocationSearchActivity extends BaseActivity {
|
|
|
search_edit.addTextChangedListener(new EditChangeListener() {
|
|
search_edit.addTextChangedListener(new EditChangeListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void afterTextChanged(Editable editable) {
|
|
public void afterTextChanged(Editable editable) {
|
|
|
- if (editable == null || StringUtils.isEmpty(editable.toString())) return;
|
|
|
|
|
|
|
+ if (editable == null) return;
|
|
|
keyWork = editable.toString();
|
|
keyWork = editable.toString();
|
|
|
- if (StringUtils.isEmpty(keyWork))
|
|
|
|
|
- loadDataByNeer();
|
|
|
|
|
- else
|
|
|
|
|
|
|
+ if (StringUtils.isEmpty(keyWork)) {
|
|
|
|
|
+ keyWork = getIntent().getStringExtra("keyWork");
|
|
|
|
|
+ if (StringUtils.isEmpty(keyWork))
|
|
|
|
|
+ loadDataByNeer();
|
|
|
|
|
+ else search();
|
|
|
|
|
+ } else
|
|
|
search();
|
|
search();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -243,34 +249,28 @@ public class LocationSearchActivity extends BaseActivity {
|
|
|
@Override
|
|
@Override
|
|
|
public void result(SearchResult result) {
|
|
public void result(SearchResult result) {
|
|
|
if (result == null) {
|
|
if (result == null) {
|
|
|
- Log.i("gongpengming", "返回为空");
|
|
|
|
|
- listData = null;
|
|
|
|
|
|
|
+ listData.clear();
|
|
|
adapter.setListData(listData);
|
|
adapter.setListData(listData);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- Log.i("gongpengming", "进来else ");
|
|
|
|
|
PoiResult poiResult = (PoiResult) result;
|
|
PoiResult poiResult = (PoiResult) result;
|
|
|
List<PoiInfo> chches = poiResult.getAllPoi();
|
|
List<PoiInfo> chches = poiResult.getAllPoi();
|
|
|
if (ListUtils.isEmpty(chches)) {
|
|
if (ListUtils.isEmpty(chches)) {
|
|
|
- Log.i("gongpengming", "chches==nulll");
|
|
|
|
|
- Log.i("gongpengming", "isChina=" + isChina);
|
|
|
|
|
if (isChina) {
|
|
if (isChina) {
|
|
|
isChina = false;
|
|
isChina = false;
|
|
|
BaiduMapUtil.getInstence().searchByInput(keyWork, pageNum, listener);
|
|
BaiduMapUtil.getInstence().searchByInput(keyWork, pageNum, listener);
|
|
|
return;
|
|
return;
|
|
|
- }
|
|
|
|
|
|
|
+ } else listData.clear();
|
|
|
} else {
|
|
} else {
|
|
|
- Log.i("gongpengming", "chches!!!!!!!!!!!!=nulll ");
|
|
|
|
|
BaiduMapUtil.getInstence().setMapViewPoint(bmapView, chches.get(0).location, true);
|
|
BaiduMapUtil.getInstence().setMapViewPoint(bmapView, chches.get(0).location, true);
|
|
|
for (int i = 0; i < chches.size(); i++) {
|
|
for (int i = 0; i < chches.size(); i++) {
|
|
|
- Log.i("gongpengming", "chches.get(i).name=" + chches.get(i).name);
|
|
|
|
|
if (StringUtils.isEmpty(chches.get(i).name) || StringUtils.isEmpty(chches.get(i).address)) {
|
|
if (StringUtils.isEmpty(chches.get(i).name) || StringUtils.isEmpty(chches.get(i).address)) {
|
|
|
chches.remove(i);
|
|
chches.remove(i);
|
|
|
i--;
|
|
i--;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ listData = chches;
|
|
|
}
|
|
}
|
|
|
- listData = chches;
|
|
|
|
|
adapter.setListData(listData);
|
|
adapter.setListData(listData);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -318,11 +318,33 @@ public class LocationSearchActivity extends BaseActivity {
|
|
|
}
|
|
}
|
|
|
holder.address_tv.setText(listData.get(i).address);
|
|
holder.address_tv.setText(listData.get(i).address);
|
|
|
holder.name_tv.setText(listData.get(i).name);
|
|
holder.name_tv.setText(listData.get(i).name);
|
|
|
- holder.distance_tv.setText(BaiduMapUtil.getInstence().
|
|
|
|
|
- getDistance(listData.get(i).location, companyLat) + " m");
|
|
|
|
|
|
|
+ holder.distance_tv.setText(getDistance(listData.get(i).location));
|
|
|
return view;
|
|
return view;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private String getDistance(LatLng location) {
|
|
|
|
|
+ String dis = BaiduMapUtil.getInstence().getDistance(location, companyLat);
|
|
|
|
|
+ if (StringUtils.isEmpty(dis)) return String.valueOf(0);
|
|
|
|
|
+ if (isKm) {
|
|
|
|
|
+ return getKm(dis) + " km";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return dis + " m";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getKm(String dis) {
|
|
|
|
|
+ if (StringUtils.isEmpty(dis)) return String.valueOf(0);
|
|
|
|
|
+ try {
|
|
|
|
|
+ DecimalFormat fnum = new DecimalFormat("##0.00");
|
|
|
|
|
+ String dd = fnum.format(Float.valueOf(dis) / 1000);
|
|
|
|
|
+ return dd;
|
|
|
|
|
+ } catch (ClassCastException e) {
|
|
|
|
|
+ return String.valueOf(0);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return String.valueOf(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
class ViewHolder {
|
|
class ViewHolder {
|
|
|
TextView name_tv, address_tv, distance_tv;
|
|
TextView name_tv, address_tv, distance_tv;
|
|
|
}
|
|
}
|