|
|
@ -16,8 +16,11 @@ import com.baidu.mapapi.map.BitmapDescriptorFactory;
|
|
|
|
import com.baidu.mapapi.map.MapStatusUpdateFactory;
|
|
|
|
import com.baidu.mapapi.map.MapStatusUpdateFactory;
|
|
|
|
import com.baidu.mapapi.map.MapView;
|
|
|
|
import com.baidu.mapapi.map.MapView;
|
|
|
|
import com.baidu.mapapi.map.MarkerOptions;
|
|
|
|
import com.baidu.mapapi.map.MarkerOptions;
|
|
|
|
|
|
|
|
import com.baidu.mapapi.map.MyLocationConfiguration;
|
|
|
|
|
|
|
|
import com.baidu.mapapi.map.MyLocationData;
|
|
|
|
import com.baidu.mapapi.map.OverlayOptions;
|
|
|
|
import com.baidu.mapapi.map.OverlayOptions;
|
|
|
|
import com.baidu.mapapi.model.LatLng;
|
|
|
|
import com.baidu.mapapi.model.LatLng;
|
|
|
|
|
|
|
|
|
|
|
|
import com.baidu.mapapi.utils.DistanceUtil;
|
|
|
|
import com.baidu.mapapi.utils.DistanceUtil;
|
|
|
|
import com.orhanobut.logger.Logger;
|
|
|
|
import com.orhanobut.logger.Logger;
|
|
|
|
|
|
|
|
|
|
|
@ -43,13 +46,16 @@ public class LocActivity extends ParentWithNaviActivity{
|
|
|
|
BaiduMap mBaiduMap = null;
|
|
|
|
BaiduMap mBaiduMap = null;
|
|
|
|
public LocationClient mLocationClient = null;
|
|
|
|
public LocationClient mLocationClient = null;
|
|
|
|
public BDLocationListener myListener = new MyLocationListener();
|
|
|
|
public BDLocationListener myListener = new MyLocationListener();
|
|
|
|
private LinkedList<LocationEntity> locationList = new LinkedList<LocationEntity>(); // 存放历史定位结果的链表,最大存放当前结果的前5次定位结果
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//BmobIMConversation c;
|
|
|
|
private MyLocationData mylocdata = null;
|
|
|
|
//ChatAdapter adapter;
|
|
|
|
private MyLocationData friendlocdata = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Toast loc_toast = null;
|
|
|
|
private LinkedList<LocationEntity> locationList = new LinkedList<LocationEntity>(); // 存放历史定位结果的链表,最大存放当前结果的前5次定位结果
|
|
|
|
|
|
|
|
int exe_count = 0;
|
|
|
|
|
|
|
|
BmobIMConversation c;
|
|
|
|
|
|
|
|
ChatAdapter adapter;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
@ -60,23 +66,32 @@ public class LocActivity extends ParentWithNaviActivity{
|
|
|
|
mLocationClient.registerLocationListener( myListener );
|
|
|
|
mLocationClient.registerLocationListener( myListener );
|
|
|
|
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_loc);
|
|
|
|
setContentView(R.layout.activity_loc);
|
|
|
|
//c= BmobIMConversation.obtain(BmobIMClient.getInstance(), (BmobIMConversation) getBundle().getSerializable("c"));
|
|
|
|
c= BmobIMConversation.obtain(BmobIMClient.getInstance(), (BmobIMConversation) getBundle().getSerializable("c"));
|
|
|
|
|
|
|
|
adapter = new ChatAdapter(this,c);
|
|
|
|
initNaviView();
|
|
|
|
initNaviView();
|
|
|
|
//initLocation();
|
|
|
|
initLocation();
|
|
|
|
mMapView = (MapView) findViewById(R.id.bmapView);
|
|
|
|
mMapView = (MapView) findViewById(R.id.bmapView);
|
|
|
|
|
|
|
|
|
|
|
|
mBaiduMap = mMapView.getMap();
|
|
|
|
mBaiduMap = mMapView.getMap();
|
|
|
|
mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
|
|
|
|
mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
|
|
|
|
|
|
|
|
|
|
|
|
// 开启定位图层
|
|
|
|
// 开启定位图层
|
|
|
|
mBaiduMap.setMyLocationEnabled(true);
|
|
|
|
|
|
|
|
mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomTo(16));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mLocationClient.start();
|
|
|
|
mLocationClient.start();
|
|
|
|
mLocationClient.requestLocation();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mBaiduMap.clear();
|
|
|
|
Logger.i("before \n");
|
|
|
|
|
|
|
|
//mLocationClient.requestLocation();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.i("after \n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//mBaiduMap.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//mLocationClient.requestLocation();
|
|
|
|
|
|
|
|
|
|
|
|
//send_recv_real_time();
|
|
|
|
//send_recv_real_time();
|
|
|
|
|
|
|
|
|
|
|
@ -114,7 +129,7 @@ public class LocActivity extends ParentWithNaviActivity{
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 消息发送监听器
|
|
|
|
* 消息发送监听器
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/* public MessageSendListener listener =new MessageSendListener() {
|
|
|
|
public MessageSendListener listener =new MessageSendListener() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onProgress(int value) {
|
|
|
|
public void onProgress(int value) {
|
|
|
@ -127,21 +142,17 @@ public class LocActivity extends ParentWithNaviActivity{
|
|
|
|
public void onStart(BmobIMMessage msg) {
|
|
|
|
public void onStart(BmobIMMessage msg) {
|
|
|
|
super.onStart(msg);
|
|
|
|
super.onStart(msg);
|
|
|
|
adapter.addMessage(msg);
|
|
|
|
adapter.addMessage(msg);
|
|
|
|
edit_msg.setText("");
|
|
|
|
|
|
|
|
scrollToBottom();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void done(BmobIMMessage msg, BmobException e) {
|
|
|
|
public void done(BmobIMMessage msg, BmobException e) {
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
edit_msg.setText("");
|
|
|
|
|
|
|
|
scrollToBottom();
|
|
|
|
|
|
|
|
if (e != null) {
|
|
|
|
if (e != null) {
|
|
|
|
toast(e.getMessage());
|
|
|
|
toast(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ParentWithNaviActivity.ToolBarListener setToolBarListener() {
|
|
|
|
public ParentWithNaviActivity.ToolBarListener setToolBarListener() {
|
|
|
|
return new ParentWithNaviActivity.ToolBarListener() {
|
|
|
|
return new ParentWithNaviActivity.ToolBarListener() {
|
|
|
@ -160,6 +171,8 @@ public class LocActivity extends ParentWithNaviActivity{
|
|
|
|
super.onDestroy();
|
|
|
|
super.onDestroy();
|
|
|
|
mLocationClient.unRegisterLocationListener( myListener );
|
|
|
|
mLocationClient.unRegisterLocationListener( myListener );
|
|
|
|
mLocationClient.stop();
|
|
|
|
mLocationClient.stop();
|
|
|
|
|
|
|
|
// 当不需要定位图层时关闭定位图层
|
|
|
|
|
|
|
|
mBaiduMap.setMyLocationEnabled(false);
|
|
|
|
//在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理
|
|
|
|
//在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理
|
|
|
|
mMapView.onDestroy();
|
|
|
|
mMapView.onDestroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -227,6 +240,7 @@ public class LocActivity extends ParentWithNaviActivity{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Logger.i(sb.toString());*/
|
|
|
|
Logger.i(sb.toString());*/
|
|
|
|
|
|
|
|
exe_count = exe_count + 1;
|
|
|
|
if (location != null && (location.getLocType() == 161 || location.getLocType() == 66)) {
|
|
|
|
if (location != null && (location.getLocType() == 161 || location.getLocType() == 66)) {
|
|
|
|
Message locMsg = locHander.obtainMessage();
|
|
|
|
Message locMsg = locHander.obtainMessage();
|
|
|
|
Bundle locData;
|
|
|
|
Bundle locData;
|
|
|
@ -237,6 +251,28 @@ public class LocActivity extends ParentWithNaviActivity{
|
|
|
|
locHander.sendMessage(locMsg);
|
|
|
|
locHander.sendMessage(locMsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringBuffer sb = new StringBuffer(256);
|
|
|
|
|
|
|
|
sb.append("execute times :");
|
|
|
|
|
|
|
|
sb.append( exe_count );
|
|
|
|
|
|
|
|
sb.append("\n");
|
|
|
|
|
|
|
|
Logger.i( sb.toString() );
|
|
|
|
|
|
|
|
mBaiduMap.setMyLocationEnabled(true);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
// 构造定位数据
|
|
|
|
|
|
|
|
MyLocationData locData = new MyLocationData.Builder()
|
|
|
|
|
|
|
|
.accuracy(location.getRadius())
|
|
|
|
|
|
|
|
// 此处设置开发者获取到的方向信息,顺时针0-360
|
|
|
|
|
|
|
|
.direction(100).latitude(location.getLatitude())
|
|
|
|
|
|
|
|
.longitude(location.getLongitude()).build();
|
|
|
|
|
|
|
|
// 设置定位数据
|
|
|
|
|
|
|
|
mBaiduMap.setMyLocationData(locData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置定位图层的配置(定位模式,是否允许方向信息,用户自定义定位图标)
|
|
|
|
|
|
|
|
BitmapDescriptor mCurrentMarker = BitmapDescriptorFactory
|
|
|
|
|
|
|
|
.fromResource(R.drawable.chat_voice_bg);
|
|
|
|
|
|
|
|
MyLocationConfiguration config = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, mCurrentMarker);
|
|
|
|
|
|
|
|
mBaiduMap.setMyLocationConfigeration(config);
|
|
|
|
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/***
|
|
|
|
/***
|
|
|
@ -331,9 +367,28 @@ public class LocActivity extends ParentWithNaviActivity{
|
|
|
|
overlayManager.setData(aslist);
|
|
|
|
overlayManager.setData(aslist);
|
|
|
|
mBaiduMap.setOnMarkerClickListener(overlayManager);
|
|
|
|
mBaiduMap.setOnMarkerClickListener(overlayManager);
|
|
|
|
overlayManager.addToMap();
|
|
|
|
overlayManager.addToMap();
|
|
|
|
overlayManager.zoomToSpan();
|
|
|
|
if( exe_count < 3)
|
|
|
|
|
|
|
|
overlayManager.zoomToSpan();
|
|
|
|
mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng( new LatLng ( (point.latitude + point2.latitude )/ 2,(point.longitude + point2.longitude)/2)) );
|
|
|
|
mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng( new LatLng ( (point.latitude + point2.latitude )/ 2,(point.longitude + point2.longitude)/2)) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BmobIMLocationMessage loc_msg =new BmobIMLocationMessage("myloc",location.getLatitude(),location.getAltitude());
|
|
|
|
|
|
|
|
c.sendMessage(loc_msg, new MessageSendListener() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onStart(BmobIMMessage msg) {
|
|
|
|
|
|
|
|
adapter.addMessage(msg);
|
|
|
|
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void done(BmobIMMessage msg, BmobException e) {
|
|
|
|
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
|
|
|
|
if (e != null) {
|
|
|
|
|
|
|
|
toast(e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO: handle exception
|
|
|
|
// TODO: handle exception
|
|
|
|