|
@@ -5,18 +5,32 @@ package com.usai.apex;
|
|
|
//import baidumapsdk.demo.DemoApplication;
|
|
//import baidumapsdk.demo.DemoApplication;
|
|
|
//import baidumapsdk.demo.DemoApplication.MyGeneralListener;
|
|
//import baidumapsdk.demo.DemoApplication.MyGeneralListener;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+
|
|
|
|
|
+import org.json.JSONException;
|
|
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
import com.baidu.mapapi.BMapManager;
|
|
import com.baidu.mapapi.BMapManager;
|
|
|
import com.baidu.mapapi.MKGeneralListener;
|
|
import com.baidu.mapapi.MKGeneralListener;
|
|
|
|
|
+import com.baidu.mapapi.map.ItemizedOverlay;
|
|
|
import com.baidu.mapapi.map.MKEvent;
|
|
import com.baidu.mapapi.map.MKEvent;
|
|
|
import com.baidu.mapapi.map.MapController;
|
|
import com.baidu.mapapi.map.MapController;
|
|
|
|
|
+import com.baidu.mapapi.map.MapView;
|
|
|
|
|
+import com.baidu.mapapi.map.OverlayItem;
|
|
|
import com.baidu.mapapi.map.SupportMapFragment;
|
|
import com.baidu.mapapi.map.SupportMapFragment;
|
|
|
import com.baidu.platform.comapi.basestruct.GeoPoint;
|
|
import com.baidu.platform.comapi.basestruct.GeoPoint;
|
|
|
|
|
+import com.usai.util.Network;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
|
|
+import android.os.AsyncTask;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.app.Fragment;
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v4.app.FragmentManager;
|
|
import android.support.v4.app.FragmentManager;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
|
|
+import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
@@ -24,11 +38,342 @@ import android.widget.Toast;
|
|
|
|
|
|
|
|
public class BaiduMapFragment extends Fragment
|
|
public class BaiduMapFragment extends Fragment
|
|
|
{
|
|
{
|
|
|
|
|
+ private SearchTask m_task = null;
|
|
|
|
|
+ String fragment_content = null;
|
|
|
|
|
+ private MapView mMapView = null;
|
|
|
|
|
+ private MyOverlay mOverlay = null;
|
|
|
|
|
+// private OverlayItem mCurItem = null;
|
|
|
|
|
+// private Button button = null;
|
|
|
|
|
+ private ArrayList<OverlayItem> mItems = null;
|
|
|
|
|
+
|
|
|
SupportMapFragment fragment;
|
|
SupportMapFragment fragment;
|
|
|
BMapManager mBMapManager = null;
|
|
BMapManager mBMapManager = null;
|
|
|
public static boolean m_bKeyRight = true;
|
|
public static boolean m_bKeyRight = true;
|
|
|
public static final String strKey = "tznWFxd3RvSoul1TGQp6GSzo";
|
|
public static final String strKey = "tznWFxd3RvSoul1TGQp6GSzo";
|
|
|
|
|
|
|
|
|
|
+ public class MyOverlay extends ItemizedOverlay{
|
|
|
|
|
+
|
|
|
|
|
+ public MyOverlay(Drawable defaultMarker, MapView mapView) {
|
|
|
|
|
+ super(defaultMarker, mapView);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onTap(int index){
|
|
|
|
|
+// OverlayItem item = getItem(index);
|
|
|
|
|
+// mCurItem = item ;
|
|
|
|
|
+// if (index == 3){
|
|
|
|
|
+// button.setText("这是一个系统控件");
|
|
|
|
|
+// GeoPoint pt = new GeoPoint((int) (mLat4 * 1E6),
|
|
|
|
|
+// (int) (mLon4 * 1E6));
|
|
|
|
|
+// // 弹出自定义View
|
|
|
|
|
+// pop.showPopup(button, pt, 32);
|
|
|
|
|
+// }
|
|
|
|
|
+// else{
|
|
|
|
|
+// popupText.setText(getItem(index).getTitle());
|
|
|
|
|
+// Bitmap[] bitMaps={
|
|
|
|
|
+// BMapUtil.getBitmapFromView(popupLeft),
|
|
|
|
|
+// BMapUtil.getBitmapFromView(popupInfo),
|
|
|
|
|
+// BMapUtil.getBitmapFromView(popupRight)
|
|
|
|
|
+// };
|
|
|
|
|
+// pop.showPopup(bitMaps,item.getPoint(),32);
|
|
|
|
|
+// }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public boolean onTap(GeoPoint pt , MapView mMapView){
|
|
|
|
|
+//// if (pop != null){
|
|
|
|
|
+//// pop.hidePop();
|
|
|
|
|
+//// mMapView.removeView(button);
|
|
|
|
|
+//// }
|
|
|
|
|
+// return false;
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ void AddMarker()
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ if (mMapView == null)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ Log.d("onResume", "get map from fragment");
|
|
|
|
|
+ mMapView = fragment.getMapView();
|
|
|
|
|
+ if (mMapView == null)
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ JSONObject jsobj = new JSONObject(fragment_content);
|
|
|
|
|
+
|
|
|
|
|
+ int count = jsobj.getInt("total");
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject objrecords = jsobj.getJSONObject("records");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < count; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ // offset++;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject objrec = objrecords.getJSONObject("record" + i);
|
|
|
|
|
+ String area = objrec.getString("area");
|
|
|
|
|
+ String company = objrec.getString("company");
|
|
|
|
|
+ String city = objrec.getString("city");
|
|
|
|
|
+ String longitude = objrec.getString("longitude");
|
|
|
|
|
+ String latitude = objrec.getString("latitude");
|
|
|
|
|
+ String address = objrec.getString("address");
|
|
|
|
|
+ String telephone = objrec.getString("telephone");
|
|
|
|
|
+ String fax = objrec.getString("fax");
|
|
|
|
|
+ String contact = objrec.getString("contact");
|
|
|
|
|
+ String email = objrec.getString("email");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ LocationDetail detail = new LocationDetail(company, address,
|
|
|
|
|
+ telephone, fax, contact, email);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ mOverlay = new MyOverlay(getResources().getDrawable(R.drawable.ic_marker),mMapView);
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 准备overlay 数据
|
|
|
|
|
+ */
|
|
|
|
|
+ GeoPoint p1 = new GeoPoint ((int)(Double.parseDouble(latitude)*1E6),(int)(Double.parseDouble(longitude)*1E6));
|
|
|
|
|
+ OverlayItem item1 = new OverlayItem(p1,company,city+"\n"+area);
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 设置overlay图标,如不设置,则使用创建ItemizedOverlay时的默认图标.
|
|
|
|
|
+// */
|
|
|
|
|
+// item1.setMarker(getResources().getDrawable(R.drawable.icon_marka));
|
|
|
|
|
+//
|
|
|
|
|
+// GeoPoint p2 = new GeoPoint ((int)(mLat2*1E6),(int)(mLon2*1E6));
|
|
|
|
|
+// OverlayItem item2 = new OverlayItem(p2,"覆盖物2","");
|
|
|
|
|
+// item2.setMarker(getResources().getDrawable(R.drawable.icon_markb));
|
|
|
|
|
+//
|
|
|
|
|
+// GeoPoint p3 = new GeoPoint ((int)(mLat3*1E6),(int)(mLon3*1E6));
|
|
|
|
|
+// OverlayItem item3 = new OverlayItem(p3,"覆盖物3","");
|
|
|
|
|
+// item3.setMarker(getResources().getDrawable(R.drawable.icon_markc));
|
|
|
|
|
+//
|
|
|
|
|
+// GeoPoint p4 = new GeoPoint ((int)(mLat4*1E6),(int)(mLon4*1E6));
|
|
|
|
|
+// OverlayItem item4 = new OverlayItem(p4,"覆盖物4","");
|
|
|
|
|
+// item4.setMarker(getResources().getDrawable(R.drawable.icon_gcoding));
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将item 添加到overlay中
|
|
|
|
|
+ * 注意: 同一个itme只能add一次
|
|
|
|
|
+ */
|
|
|
|
|
+ mOverlay.addItem(item1);
|
|
|
|
|
+// mOverlay.addItem(item2);
|
|
|
|
|
+// mOverlay.addItem(item3);
|
|
|
|
|
+// mOverlay.addItem(item4);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存所有item,以便overlay在reset后重新添加
|
|
|
|
|
+ */
|
|
|
|
|
+ mItems = new ArrayList<OverlayItem>();
|
|
|
|
|
+ mItems.addAll(mOverlay.getAllItem());
|
|
|
|
|
+
|
|
|
|
|
+// // 初始化 ground 图层
|
|
|
|
|
+// mGroundOverlay = new GroundOverlay(mMapView);
|
|
|
|
|
+// GeoPoint leftBottom = new GeoPoint((int) (mLat5 * 1E6),
|
|
|
|
|
+// (int) (mLon5 * 1E6));
|
|
|
|
|
+// GeoPoint rightTop = new GeoPoint((int) (mLat6 * 1E6),
|
|
|
|
|
+// (int) (mLon6 * 1E6));
|
|
|
|
|
+// Drawable d = getResources().getDrawable(R.drawable.ground_overlay);
|
|
|
|
|
+// Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
|
|
|
|
|
+// mGround = new Ground(bitmap, leftBottom, rightTop);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将overlay 添加至MapView中
|
|
|
|
|
+ */
|
|
|
|
|
+ mMapView.getOverlays().add(mOverlay);
|
|
|
|
|
+// mMapView.getOverlays().add(mGroundOverlay);
|
|
|
|
|
+// mGroundOverlay.addGround(mGround);
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 刷新地图
|
|
|
|
|
+ */
|
|
|
|
|
+ mMapView.refresh();
|
|
|
|
|
+// mResetBtn.setEnabled(false);
|
|
|
|
|
+// mClearBtn.setEnabled(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (JSONException e)
|
|
|
|
|
+ {
|
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ public void requestloactions()
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ if (m_task != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (fragment_content != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ // LayoutInflater inflater = (LayoutInflater)
|
|
|
|
|
+ // ApexTrackingApplication
|
|
|
|
|
+ // .get_instance().getSystemService(
|
|
|
|
|
+ // Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
+ // init(fragment_content,inflater);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // mStatusMessageView.setText(R.string.str_Loading);
|
|
|
|
|
+ // showProgress(true);
|
|
|
|
|
+ m_task = new SearchTask();
|
|
|
|
|
+
|
|
|
|
|
+ // TextView text_page = (TextView) view_page_footer
|
|
|
|
|
+ // .findViewById(R.id.text_page);
|
|
|
|
|
+ // text_page.setText("Loading...");
|
|
|
|
|
+ // text_page.setEnabled(false);
|
|
|
|
|
+ m_task.execute();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ class SearchTask extends AsyncTask<Void, Void, Boolean>
|
|
|
|
|
+ {
|
|
|
|
|
+ int errorcode;
|
|
|
|
|
+
|
|
|
|
|
+ // boolean bfinish = false;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected Boolean doInBackground(Void... params)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log.d("SearchTask", "doInBackground");
|
|
|
|
|
+ if (!Network.NetworkIsAvailable())
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ errorcode = Network.RESULT_NET_NOTAVAILABLE;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ String jstr = Network.get_servicelocation();
|
|
|
|
|
+
|
|
|
|
|
+ if (jstr == null || jstr.length() <= 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Log.d(TAG, "json is wrong");
|
|
|
|
|
+
|
|
|
|
|
+ errorcode = Network.RESULT_NET_ERROR;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject jsobj;
|
|
|
|
|
+ //
|
|
|
|
|
+ // array = new JSONArray(json);
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ jsobj = new JSONObject(jstr);
|
|
|
|
|
+ // if (searchresult.get_fieldscount() == 0)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // JSONObject objfields = jsobj.getJSONObject("fields");
|
|
|
|
|
+ // if (objfields != null)
|
|
|
|
|
+ // searchresult.init_fields(objfields.toString());
|
|
|
|
|
+ // }
|
|
|
|
|
+ int count = jsobj.getInt("total");
|
|
|
|
|
+ // if (count < limit)
|
|
|
|
|
+ // bfinish = true;
|
|
|
|
|
+ JSONObject objrecords = jsobj.getJSONObject("records");
|
|
|
|
|
+ if (objrecords != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ fragment_content = jstr;
|
|
|
|
|
+ errorcode = Network.RESULT_TRUE;
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (JSONException e)
|
|
|
|
|
+ {
|
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ errorcode = Network.RESULT_NET_ERROR;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onPostExecute(Boolean success)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log.i("onPostExecute", "entry");
|
|
|
|
|
+ m_task = null;
|
|
|
|
|
+ // showProgress(false);
|
|
|
|
|
+
|
|
|
|
|
+ switch (errorcode)
|
|
|
|
|
+ {
|
|
|
|
|
+ case Network.RESULT_NET_NOTAVAILABLE:
|
|
|
|
|
+ {
|
|
|
|
|
+ Toast toast = Toast.makeText(
|
|
|
|
|
+ ApexTrackingApplication.get_instance(),
|
|
|
|
|
+ getText(R.string.msg_connection_none),
|
|
|
|
|
+ Toast.LENGTH_LONG);
|
|
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
|
|
+ toast.show();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case Network.RESULT_NET_ERROR:
|
|
|
|
|
+ {
|
|
|
|
|
+ Toast toast = Toast.makeText(
|
|
|
|
|
+ ApexTrackingApplication.get_instance(),
|
|
|
|
|
+ getText(R.string.msg_net_error), Toast.LENGTH_LONG);
|
|
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
|
|
+ toast.show();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case Network.RESULT_ERROR:
|
|
|
|
|
+ // case Network.RESULT_RESPONSE_NULL:
|
|
|
|
|
+ {
|
|
|
|
|
+ Toast toast = Toast.makeText(
|
|
|
|
|
+ ApexTrackingApplication.get_instance(),
|
|
|
|
|
+ getText(R.string.msg_net_resulterror),
|
|
|
|
|
+ Toast.LENGTH_LONG);
|
|
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
|
|
+ toast.show();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (success)
|
|
|
|
|
+ {
|
|
|
|
|
+ AddMarker();
|
|
|
|
|
+ //
|
|
|
|
|
+ // if (bfinish)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // // getListView().removeFooterView(view_page_footer);
|
|
|
|
|
+ // // Toast.makeText(AnnouncementActivity.this, "Load all!",
|
|
|
|
|
+ // // Toast.LENGTH_LONG).show();
|
|
|
|
|
+ //
|
|
|
|
|
+ // TextView tv = (TextView) view_page_footer
|
|
|
|
|
+ // .findViewById(R.id.text_page);
|
|
|
|
|
+ // tv.setText("No more items");
|
|
|
|
|
+ // tv.setEnabled(false);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // else
|
|
|
|
|
+ // {
|
|
|
|
|
+ // TextView tv = (TextView) view_page_footer
|
|
|
|
|
+ // .findViewById(R.id.text_page);
|
|
|
|
|
+ // tv.setText("More...");
|
|
|
|
|
+ // tv.setEnabled(true);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // adapter.notifyDataSetChanged();
|
|
|
|
|
+ // // getListAdapter().notifyDataSetChanged;
|
|
|
|
|
+ // // BaseAdapter mJson = null;
|
|
|
|
|
+ // // mJson.notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ super.onPostExecute(success);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onCancelled()
|
|
|
|
|
+ {
|
|
|
|
|
+ m_task = null;
|
|
|
|
|
+ // showProgress(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public void initEngineManager(Context context) {
|
|
public void initEngineManager(Context context) {
|
|
|
if (mBMapManager == null) {
|
|
if (mBMapManager == null) {
|
|
|
mBMapManager = new BMapManager(context);
|
|
mBMapManager = new BMapManager(context);
|
|
@@ -84,6 +429,7 @@ public class BaiduMapFragment extends Fragment
|
|
|
|
|
|
|
|
FragmentManager fm = getChildFragmentManager();
|
|
FragmentManager fm = getChildFragmentManager();
|
|
|
fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
|
|
fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
|
|
|
|
|
+
|
|
|
if (fragment == null)
|
|
if (fragment == null)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -91,6 +437,7 @@ public class BaiduMapFragment extends Fragment
|
|
|
fragment = SupportMapFragment.newInstance();;// .newInstance();
|
|
fragment = SupportMapFragment.newInstance();;// .newInstance();
|
|
|
fm.beginTransaction().replace(R.id.map, fragment).commit();
|
|
fm.beginTransaction().replace(R.id.map, fragment).commit();
|
|
|
}
|
|
}
|
|
|
|
|
+ mMapView = fragment.getMapView();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -99,6 +446,7 @@ public class BaiduMapFragment extends Fragment
|
|
|
{
|
|
{
|
|
|
// TODO Auto-generated method stub
|
|
// TODO Auto-generated method stub
|
|
|
// return super.onCreateView(inflater, container, savedInstanceState);
|
|
// return super.onCreateView(inflater, container, savedInstanceState);
|
|
|
|
|
+ requestloactions();
|
|
|
return inflater.inflate(R.layout.fragment_service_location, container,
|
|
return inflater.inflate(R.layout.fragment_service_location, container,
|
|
|
false);
|
|
false);
|
|
|
}
|
|
}
|