|
|
@@ -2,32 +2,32 @@ package com.xzjmyk.pm.activity.ui.erp.activity.oa;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
import android.util.Log;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.BaseAdapter;
|
|
|
+import android.widget.CheckBox;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
-import com.baidu.mapapi.map.BaiduMap;
|
|
|
import com.baidu.mapapi.map.BitmapDescriptor;
|
|
|
import com.baidu.mapapi.map.BitmapDescriptorFactory;
|
|
|
import com.baidu.mapapi.map.MapStatus;
|
|
|
import com.baidu.mapapi.map.MapStatusUpdate;
|
|
|
import com.baidu.mapapi.map.MapStatusUpdateFactory;
|
|
|
import com.baidu.mapapi.map.MapView;
|
|
|
-import com.baidu.mapapi.map.Marker;
|
|
|
import com.baidu.mapapi.map.MarkerOptions;
|
|
|
import com.baidu.mapapi.map.OverlayOptions;
|
|
|
import com.baidu.mapapi.model.LatLng;
|
|
|
import com.baidu.mapapi.search.core.PoiInfo;
|
|
|
-import com.baidu.mapapi.search.core.SearchResult;
|
|
|
-import com.baidu.mapapi.search.geocode.GeoCodeResult;
|
|
|
-import com.baidu.mapapi.search.geocode.GeoCoder;
|
|
|
-import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
|
|
|
-import com.baidu.mapapi.search.geocode.ReverseGeoCodeOption;
|
|
|
-import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
|
|
|
import com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;
|
|
|
import com.baidu.mapapi.search.poi.PoiDetailResult;
|
|
|
-import com.baidu.mapapi.search.poi.PoiIndoorInfo;
|
|
|
import com.baidu.mapapi.search.poi.PoiIndoorResult;
|
|
|
import com.baidu.mapapi.search.poi.PoiNearbySearchOption;
|
|
|
import com.baidu.mapapi.search.poi.PoiResult;
|
|
|
import com.baidu.mapapi.search.poi.PoiSearch;
|
|
|
+import com.baidu.mapapi.search.poi.PoiSortType;
|
|
|
+import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
|
|
import com.xzjmyk.pm.activity.BdLocationHelper;
|
|
|
import com.xzjmyk.pm.activity.MyApplication;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
@@ -36,128 +36,184 @@ import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
import java.util.List;
|
|
|
|
|
|
//选择地址
|
|
|
-public class LocationMapActivity extends BaseActivity {
|
|
|
-
|
|
|
+public class LocationMapActivity extends BaseActivity implements OnGetPoiSearchResultListener {
|
|
|
+ double latitude;
|
|
|
+ double longitude;
|
|
|
private MapView mapView;
|
|
|
- private GeoCoder coder;
|
|
|
+ private PullToRefreshListView listView;
|
|
|
+ private List<PoiInfo> listData;
|
|
|
+ private PoiNearbySearchOption option = null;
|
|
|
+ private PoiSearch mPoiSearch;
|
|
|
+ private LocationMapAdapter adapter;
|
|
|
+ private int selectItem = 0;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_select_location2);
|
|
|
+ setContentView(R.layout.activity_map_location);
|
|
|
+ init();
|
|
|
+ initView();
|
|
|
+ listenerNearInfo(0, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initView() {
|
|
|
mapView = (MapView) findViewById(R.id.bmapView);
|
|
|
+ listView = (PullToRefreshListView) findViewById(R.id.listview);
|
|
|
+ initMapViewSet();
|
|
|
+ adapter = new LocationMapAdapter();
|
|
|
+ listView.setAdapter(adapter);
|
|
|
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
+ selectItem = i - 1;
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ initMapViewSet(listData.get(i - 1).location);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void init() {
|
|
|
BdLocationHelper locationHelper = MyApplication.getInstance().getBdLocationHelper();
|
|
|
latitude = locationHelper.getLatitude();
|
|
|
longitude = locationHelper.getLongitude();
|
|
|
- setMapViewSet();
|
|
|
- setNearMap();
|
|
|
- dosame();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- private void setNearMap() {
|
|
|
-
|
|
|
+ //监听周围信息的获取 radius=0 为默认显示周围1000米
|
|
|
+ private void listenerNearInfo(int radius, int pagerNum) {
|
|
|
+ if (option == null) { //当。。。。
|
|
|
+ option = new PoiNearbySearchOption();
|
|
|
+ option.keyword("写字楼");
|
|
|
+ option.sortType(PoiSortType.distance_from_near_to_far);
|
|
|
+ option.location(new LatLng(latitude, longitude));
|
|
|
+ if (radius != 0) {
|
|
|
+ option.radius(radius);
|
|
|
+ } else {
|
|
|
+ option.radius(1000);
|
|
|
+ }
|
|
|
+ if (pagerNum != 0) {
|
|
|
+ option.pageNum(pagerNum);
|
|
|
+ } else {
|
|
|
+ option.pageNum(1);
|
|
|
+ }
|
|
|
+ option.pageCapacity(20);
|
|
|
+ }
|
|
|
+ mPoiSearch = PoiSearch.newInstance();
|
|
|
+ mPoiSearch.setOnGetPoiSearchResultListener(this);
|
|
|
+ mPoiSearch.searchNearby(option);
|
|
|
}
|
|
|
|
|
|
- double latitude;
|
|
|
- double longitude;
|
|
|
-
|
|
|
- private void setMapViewSet() {
|
|
|
+ //显示当前位置
|
|
|
+ private void initMapViewSet() {
|
|
|
// 定义Maker坐标点
|
|
|
-
|
|
|
LatLng point = new LatLng(latitude, longitude);
|
|
|
// 构建Marker图标
|
|
|
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
|
|
|
// 构建MarkerOption,用于在地图上添加Marker
|
|
|
- OverlayOptions option = new MarkerOptions().position(point).icon(bitmap).title("显示题图");
|
|
|
+ OverlayOptions option = new MarkerOptions().position(point).icon(bitmap);
|
|
|
// 在地图上添加Marker,并显示
|
|
|
mapView.getMap().addOverlay(option);
|
|
|
-
|
|
|
MapStatus mapStatus = new MapStatus.Builder().zoom(mapView.getMap().getMaxZoomLevel() - 3).target(point).build();
|
|
|
MapStatusUpdate u = MapStatusUpdateFactory.newMapStatus(mapStatus);
|
|
|
mapView.getMap().animateMapStatus(u);//设置为中心显示
|
|
|
-
|
|
|
- mapView.getMap().setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
|
|
|
- @Override
|
|
|
- public boolean onMarkerClick(Marker arg0) {
|
|
|
- Log.i("gongpengming", "点击地图");
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- private void nearbySearch(int page) {
|
|
|
- BdLocationHelper h = MyApplication.getInstance().getBdLocationHelper();
|
|
|
- final LatLng geolat = new LatLng(h.getLatitude(), h.getLongitude());
|
|
|
- PoiNearbySearchOption nearbySearchOption = new PoiNearbySearchOption();
|
|
|
- nearbySearchOption.location(geolat);
|
|
|
- nearbySearchOption.keyword("银行");
|
|
|
- nearbySearchOption.radius(1000);// 检索半径,单位是米
|
|
|
- nearbySearchOption.pageNum(page);
|
|
|
- PoiSearch poiSearch = PoiSearch.newInstance();
|
|
|
- poiSearch.searchNearby(nearbySearchOption);// 发起附近检索请求
|
|
|
- poiSearch.setOnGetPoiSearchResultListener(new OnGetPoiSearchResultListener() {
|
|
|
- @Override
|
|
|
- public void onGetPoiResult(PoiResult poiResult) {
|
|
|
-// List<PoiAddrInfo> lis = poiResult.getAllAddr();
|
|
|
-// for (int i = 0; i < lis.size(); i++) {
|
|
|
-// Log.i("gongpengminga", lis.get(i).address);
|
|
|
-// }
|
|
|
- if (poiResult.error != SearchResult.ERRORNO.NO_ERROR) {
|
|
|
- Log.i("gongpengminga", "抱歉,未找到结果");
|
|
|
-
|
|
|
- } else {
|
|
|
- Log.i("gongpengminga", "成功,查看详情页面");
|
|
|
- Log.i("gongpengminga", poiResult.getAllAddr() == null ? "为空的" : "不为空");
|
|
|
- }
|
|
|
+ //更新为选择的位置
|
|
|
+ private void initMapViewSet(LatLng latLng) {
|
|
|
+ // 构建Marker图标
|
|
|
+ BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
|
|
|
+ // 构建MarkerOption,用于在地图上添加Marker
|
|
|
+ OverlayOptions option = new MarkerOptions().position(latLng).icon(bitmap);
|
|
|
+ // 在地图上添加Marker,并显示
|
|
|
+ mapView.getMap().clear();
|
|
|
+ mapView.getMap().addOverlay(option);
|
|
|
+ MapStatus mapStatus = new MapStatus.Builder().zoom(mapView.getMap().getMaxZoomLevel() - 3).target(latLng).build();
|
|
|
+ MapStatusUpdate u = MapStatusUpdateFactory.newMapStatus(mapStatus);
|
|
|
+ mapView.getMap().animateMapStatus(u);//设置为中心显示
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onGetPoiResult(PoiResult poiResult) {
|
|
|
+
|
|
|
+ if (poiResult != null) {
|
|
|
+ listData = poiResult.getAllPoi();
|
|
|
+ if (listData != null && listData.size() > 0) {
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ } else {
|
|
|
+ //当前没有获取到数据
|
|
|
+ Log.i("gongpengming", "数据为空");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onGetPoiDetailResult(PoiDetailResult poiDetailResult) {
|
|
|
- Log.i("gongpengmingb", poiDetailResult.getAddress());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onGetPoiDetailResult(PoiDetailResult poiDetailResult) {
|
|
|
|
|
|
- @Override
|
|
|
- public void onGetPoiIndoorResult(PoiIndoorResult poiIndoorResult) {
|
|
|
- List<PoiIndoorInfo> list = poiIndoorResult.getmArrayPoiInfo();
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- Log.i("gongpengmingc", list.get(i).address);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
- private void dosame() {
|
|
|
+ @Override
|
|
|
+ public void onGetPoiIndoorResult(PoiIndoorResult poiIndoorResult) {
|
|
|
+ }
|
|
|
|
|
|
- ReverseGeoCodeOption option = new ReverseGeoCodeOption();
|
|
|
- option.location(new LatLng(latitude, longitude));
|
|
|
- coder = GeoCoder.newInstance();
|
|
|
- coder.reverseGeoCode(option);
|
|
|
- coder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {
|
|
|
- @Override
|
|
|
- public void onGetReverseGeoCodeResult(
|
|
|
- ReverseGeoCodeResult result) {
|
|
|
- List<PoiInfo> lis = result.getPoiList();
|
|
|
- for (int i = 0; i < lis.size(); i++) {
|
|
|
|
|
|
- }
|
|
|
+ class LocationMapAdapter extends BaseAdapter {
|
|
|
+ @Override
|
|
|
+ public int getCount() {
|
|
|
+ if (listData == null) {
|
|
|
+ return 0;
|
|
|
}
|
|
|
+ return listData.size();
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void onGetGeoCodeResult(GeoCodeResult arg0) {
|
|
|
-
|
|
|
+ @Override
|
|
|
+ public Object getItem(int i) {
|
|
|
+ if (listData == null) {
|
|
|
+ return 0;
|
|
|
}
|
|
|
- });
|
|
|
+ return listData.get(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long getItemId(int i) {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getView(int i, View view, ViewGroup viewGroup) {
|
|
|
+ ViewHolder holder = null;
|
|
|
+ if (view == null) {
|
|
|
+ view = LayoutInflater.from(LocationMapActivity.this).inflate(R.layout.item_location_ls, null);
|
|
|
+ holder = new ViewHolder();
|
|
|
+ holder.address_tv = (TextView) view.findViewById(R.id.address_tv);
|
|
|
+ holder.name_tv = (TextView) view.findViewById(R.id.name_tv);
|
|
|
+ holder.select_rb = (CheckBox) view.findViewById(R.id.select_rb);
|
|
|
+ view.setTag(holder);
|
|
|
+ } else {
|
|
|
+ holder = (ViewHolder) view.getTag();
|
|
|
+ }
|
|
|
+ holder.address_tv.setText(listData.get(i).address);
|
|
|
+ holder.name_tv.setText(listData.get(i).name);
|
|
|
+ if (selectItem == i) {
|
|
|
+ holder.select_rb.setChecked(true);
|
|
|
+ } else {
|
|
|
+ holder.select_rb.setChecked(false);
|
|
|
+ }
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+
|
|
|
+ class ViewHolder {
|
|
|
+ TextView name_tv, address_tv;
|
|
|
+ CheckBox select_rb;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
- if (coder != null)
|
|
|
- coder.destroy();
|
|
|
+ if (mPoiSearch != null) {
|
|
|
+ mPoiSearch.destroy();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|