Android 基於高德地圖路徑規劃
現在市面上很火的健身app、運動app等都會涉及到基於高德或者百度的路徑規劃等相關的實現,今天來和大家介紹一下Android 基於高德地圖路徑規劃。
首先說一下具體用到的jar及具體實現思路:
我用的高德jar(AMap3DMap_3.3.2_AMapNavi_1.8.0_AMapSearch_3.3.0_AMapLocation_2.6.0_20160628),
(具體高德的開發壞境配置參考http://lbs.amap.com/api/android-sdk/guide/project/)
路徑規劃(起點,終點,高德可設置16個途經點)
1.首先是高德定位,開始設置起點的位置默認在定位點,點擊設置起點,然後自動替換設置終點,然後同過地圖拖動選點來設置終點,終點設置過後,默認顯示設置設置途經點1,以此類推。當有起點和終點是地圖就會開始規劃路線;
2.規劃路線設置到增刪改查功能,增加地圖選點則是,拖動地圖選點;刪除地圖點,選擇當前已經選中的地圖選點位置刪除該地圖點,路線重新計算規劃;修改途經點,選擇當前選中的地圖點,該地圖點被選中,處於被修改狀態,拖動地圖,使得該地圖點待修改點處於待確定狀態,點擊確定選點,則修改了該地圖選點。
3.路徑規劃還有搜索地點來設置地圖選點的位置,搜索界面談起新的界面。
4.當你規劃的路徑規劃好哦,點擊完成生成路徑規劃地圖照片及起點終點途經點的位置集合(這裏的數據可以供導航等使用)。
接下來不廢話直接上代碼:
1.線路規劃界面xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearlayout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/M323535"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.motoband.ui.activity.AddRoute2Activity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp44"
android:background="@color/M00312D"
android:orientation="horizontal">
<ImageView
android:id="@+id/img_back"
android:layout_width="@dimen/dp24"
android:layout_height="@dimen/dp24"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/dp3"
android:layout_marginStart="@dimen/dp3"
android:layout_centerVertical="true"
android:background="@drawable/select_image_finsh"
android:contentDescription="@null" />
<TextView
android:id="@+id/txt_back"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:singleLine="true"
android:layout_toRightOf="@+id/img_back"
android:layout_toEndOf="@+id/img_back"
android:text="@string/img_finish"
android:textColor="@drawable/text_selector"
android:textSize="18sp" />
<TextView
android:id="@+id/txt_my_route"
android:layout_width="match_parent"
android:layout_height="@dimen/dp44"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/txt_new_route"
android:textColor="@color/MFFCE00"
android:textSize="@dimen/sp20" />
<TextView
android:id="@+id/txt_add_route"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="@dimen/dp11"
android:layout_marginStart="@dimen/dp11"
android:layout_marginRight="@dimen/dp16"
android:layout_marginEnd="@dimen/dp16"
android:text="@string/finish"
android:textColor="@drawable/text_selector"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_search"
android:layout_width="match_parent"
android:layout_height="58dp"
android:background="@color/M4A4A4A">
<EditText
android:id="@+id/edt_search_via_point"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/dp10"
android:layout_marginLeft="@dimen/dp10"
android:layout_marginRight="@dimen/dp10"
android:layout_marginTop="@dimen/dp10"
android:background="@drawable/shape_white"
android:bufferType="editable"
android:drawableLeft="@mipmap/me_find_icon_light_2"
android:drawablePadding="@dimen/dp6"
android:drawableStart="@mipmap/me_find_icon_light_2"
android:ellipsize="end"
android:gravity="center|start"
android:hint="@string/txt_search"
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLength="11"
android:textColor="@color/MFFFFFF"
android:textColorHint="@color/MC8C8C8"
android:textCursorDrawable="@drawable/shape_cursor_color"
android:textSize="@dimen/sp16" />
<LinearLayout
android:id="@+id/layout_delete"
android:layout_width="@dimen/dp50"
android:layout_height="@dimen/dp50"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone">
<ImageView
android:id="@+id/img_delete_telephone"
android:layout_width="@dimen/dp16"
android:layout_height="@dimen/dp16"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/dp24"
android:layout_marginStart="@dimen/dp24"
android:background="@mipmap/nember_button_del_2"
android:contentDescription="@null" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_map"
android:layout_width="match_parent"
android:layout_height="@dimen/dp300">
<com.amap.api.maps.MapView
android:id="@+id/mv_map"
android:layout_width="match_parent"
android:layout_height="@dimen/dp300" />
<ImageView
android:id="@+id/img_current_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:contentDescription="@null" />
<TextView
android:id="@+id/txt_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="@color/MFFFFFF"
android:layout_marginTop="101dp"
/>
<TextView
android:id="@+id/txt_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="@color/MFFFFFF"
android:layout_marginTop="123dp"
/>
<ImageView
android:id="@+id/img_map_location_type_locate"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="@dimen/dp10"
android:layout_marginEnd="@dimen/dp10"
android:layout_marginRight="@dimen/dp10"
android:contentDescription="@null"
android:src="@mipmap/compass_button_one" />
</RelativeLayout>
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
/>
<!--<ScrollView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent">-->
<!--<RelativeLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent">-->
<!--<!–//添加途經點按鈕–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_add"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:layout_marginTop="@dimen/dp22">-->
<!--<ImageView-->
<!--android:id="@+id/img_route_add"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_add"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<!–//起始地點–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_start"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:orientation="horizontal">-->
<!--<ImageView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp23"-->
<!--android:layout_marginLeft="@dimen/dp23"-->
<!--android:layout_marginRight="@dimen/dp23"-->
<!--android:layout_marginStart="@dimen/dp23"-->
<!--android:background="@drawable/shape_setup_green"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_start"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:checked="true"-->
<!--android:clickable="true"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_start"-->
<!--android:textColor="@color/MFFFFFF"-->
<!--/>-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途經點1–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_one"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_one"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_one"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_one"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–//途經點2–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_two"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_via_one"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_two"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_two"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_two"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_two"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–//途經點3–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_there"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_via_two"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_there"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_there"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_there"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_there"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途經點4–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_four"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_four"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_four"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_four"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–//途徑點5–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_five"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_five"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_five"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_five"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途徑點6–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_six"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_six"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_six"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_six"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途徑點7–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_seven"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_seven"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_seven"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_seven"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途徑點8–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_eight"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_eight"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_eight"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_eight"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途徑點9–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_nine"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_nine"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_nine"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_nine"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途徑點10–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_ten"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_ten"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_ten"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_ten"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途徑點11–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_eleven"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_eleven"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_eleven"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_eleven"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途徑點12–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_twelve"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_twelve"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_twelve"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_twelve"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途徑點13–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_thirteen"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_thirteen"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_thirteen"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_thirteen"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途徑點14–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_fourteen"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_fourteen"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_fourteen"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_fourteen"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–//途經點15–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_fifteen"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_fifteen"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_fifteen"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_fifteen"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–途經點16–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_via_sixteen"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_start"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="gone">-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_roate_via_sixteen"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44">-->
<!--<ImageView-->
<!--android:id="@+id/img_roate_via_sixteen"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_delete"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_via_sixteen"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_via_one"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--<!–//結束點–>-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_end"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_below="@+id/layout_route_via_there"-->
<!--android:orientation="horizontal">-->
<!--<RelativeLayout-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="match_parent">-->
<!--<ImageView-->
<!--android:id="@+id/img_route_end"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_centerVertical="true"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp23"-->
<!--android:layout_marginLeft="@dimen/dp23"-->
<!--android:layout_marginRight="@dimen/dp23"-->
<!--android:layout_marginStart="@dimen/dp23"-->
<!--android:background="@drawable/shape_setup_red"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--<LinearLayout-->
<!--android:id="@+id/layout_route_end_add"-->
<!--android:layout_width="@dimen/dp55"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:layout_centerVertical="true"-->
<!--android:visibility="invisible">-->
<!--<!–//添加途經點按鈕–>-->
<!--<ImageView-->
<!--android:id="@+id/img_route_end_add"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:layout_marginEnd="@dimen/dp19"-->
<!--android:layout_marginLeft="@dimen/dp19"-->
<!--android:layout_marginRight="@dimen/dp19"-->
<!--android:layout_marginStart="@dimen/dp19"-->
<!--android:background="@mipmap/position_add"-->
<!--android:contentDescription="@null"-->
<!--android:gravity="center" />-->
<!--</LinearLayout>-->
<!--</RelativeLayout>-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:orientation="vertical">-->
<!--<TextView-->
<!--android:id="@+id/txt_route_end"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp40"-->
<!--android:gravity="center|start"-->
<!--android:paddingEnd="0dp"-->
<!--android:paddingLeft="@dimen/dp7"-->
<!--android:paddingRight="0dp"-->
<!--android:paddingStart="@dimen/dp7"-->
<!--android:singleLine="true"-->
<!--android:text="@string/txt_route_end"-->
<!--android:textColor="@color/M828282" />-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp1"-->
<!--android:background="@color/MA3A3A3" />-->
<!--</LinearLayout>-->
<!--</LinearLayout>-->
<!--</RelativeLayout>-->
<!--</ScrollView>-->
</LinearLayout>
activity界面:
package com.motoband.ui.activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Environment;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapOptions;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.LatLngBounds;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.maps.overlay.DrivingRouteOverlay;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.amap.api.services.help.Tip;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import com.amap.api.services.route.BusRouteResult;
import com.amap.api.services.route.DrivePath;
import com.amap.api.services.route.DriveRouteResult;
import com.amap.api.services.route.DriveStep;
import com.amap.api.services.route.RouteSearch;
import com.amap.api.services.route.WalkRouteResult;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.motoband.R;
import com.motoband.core.manager.LoginManager;
import com.motoband.core.manager.RouteManager;
import com.motoband.core.manager.callback.MBCallback;
import com.motoband.core.model.RouteModel;
import com.motoband.core.model.RoutePointModel;
import com.motoband.core.model.UserGarageModel;
import com.motoband.core.utils.MBUtil;
import com.motoband.core.utils.ToastUtil;
import com.motoband.kprogresshud.KProgressHUD;
import com.motoband.ui.manager.PixelOrdpManager;
import com.motoband.ui.manager.StatusBarManager;
import com.motoband.ui.view.CircleImageView;
import com.umeng.analytics.MobclickAgent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AddRoute2Activity extends AppCompatActivity implements LocationSource, AMapLocationListener, GeocodeSearch.OnGeocodeSearchListener, RouteSearch.OnRouteSearchListener {
/**
* 高德地圖
*/
private MapView mapView;
private AMap aMap;
//定位點
double latitude;// 緯度
double longitude;// 經度
//地圖中心點
Marker rallyMark;
// 獲取當前地圖中心點的座標
LatLng mTarget;
//定位
private AMapLocationClient mLocationClient;
private LocationSource.OnLocationChangedListener mListener;
private EditText edt_search_via_point;
//搜索
// private PoiSearch.Query query;// Poi查詢條件類
// private PoiResult poiResult; // poi返回的結果
// private ArrayList<PoiItem> poiItemList = new ArrayList<PoiItem>();// poi數據
// int currentPage = 0;
private GeocodeSearch geocodeSearch;
private LatLonPoint latLonPoint;
//移動到當前定位點
private ImageView img_map_location_type_locate;
//完成提交按鈕
private TextView txt_add_route;
// //結束點 紅點
// private ImageView img_route_end;
// //結束點 位置上的添加按鈕
// private LinearLayout layout_route_end_add;
// private ImageView img_route_end_add;
//地圖中顯示的中心點的照片
private ImageView img_current_position;
//up down
private TextView txt_up;
private TextView txt_down;
//地圖中心點當前的具體位置
private String currentSpecificPosition;
// //判斷 開始點 途經點1 途經點2 途經點3 結束點
// private int currentShowPoint = 1;//1 2 3 4 5
private DriveRouteResult mDriveRouteResult;
//第三個參數表示途經點(最多支持16個)
List<LatLonPoint> latLonPointList = new ArrayList<LatLonPoint>();
RouteSearch routeSearch;
KProgressHUD first_hud;
//提交轉圈的動畫
KProgressHUD hud;
//完成提交的數據
private RouteModel routeModel;
// ArrayList<RoutePointModel> routePointModelArrayList = new ArrayList<RoutePointModel>();
long mileage;
String imgUrl;
//搜索途經點的回調
private boolean isShowActivityForResult = false;
private boolean isShowMoveLocationCenter = true;
//顯示開始點 結束點位置
private boolean isShowVisibleArea = false;
//點此設置集結點
public static final int SEARCH_VIA_POINT = 16;
public static final int SEARCH_VIA_POINT_FOR_RESULT = 165;
private ProgressDialog progDialog = null;// 搜索時進度條
private Intent intent;
private boolean isEdit = false;
private TextView txt_my_route;
//標記
private Marker startMark;
// private Marker viaOneMark;
// private Marker viaTwoMark;
// private Marker viaThereMark;
// private Marker viaFourMark;
// private Marker viaFiveMark;
// private Marker viaSixMark;
// private Marker viaSevenMark;
// private Marker viaEightMark;
// private Marker viaNineMark;
// private Marker viaTenMark;
// private Marker viaElevenMark;
// private Marker viaTwelveMark;
// private Marker viaThirteenMark;
// private Marker viaFourteenMark;
// private Marker viaFifteenMark;
// private Marker viaSixteenMark;
private Marker endMark;
private ListView listView;
private ViaAdapter viaAdapter;
//開始點 途徑點 終點的集合
ArrayList<RoutePointModel> routePointModelArrayList = new ArrayList<RoutePointModel>();
//判斷 開始點 途經點1 途經點2 途經點3 結束點
private int currentShowPoint = 0;//0 1 2 3 4 5
private Map<String, Marker> viaMakerMap = new HashMap<>();// 途經點
//路書的編輯返回
public static final int EDIT_ROUTE_FINISH_FOR_RESULT = 22;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_route2);
//狀態欄顏色的設置
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearlayout_main);
StatusBarManager.SetStatusBar(getWindow(), this, getResources(), "#00312D", linearLayout);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
mapView = (MapView) findViewById(R.id.mv_map);
mapView.onCreate(savedInstanceState);
routeModel = new RouteModel();
initMap();
initFindView();
loadTheData();
listenerView();
initBroadcaseReciver();
}
private void initMap() {
if (aMap == null) {
aMap = mapView.getMap();
}
UiSettings mUiSettings = aMap.getUiSettings();
mUiSettings.setZoomControlsEnabled(false);// 是否顯示放大縮小按鈕
mUiSettings.setMyLocationButtonEnabled(false);// 是否顯示定位按鈕
mUiSettings.setCompassEnabled(false);// 是否顯示指南針
mUiSettings.setScaleControlsEnabled(false); // 是否顯示比例尺
mUiSettings.setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_LEFT);// logo位置
//she
aMap.setMapType(AMap.MAP_TYPE_NIGHT);
/**
* 自定義定位圖標
*/
setMyLocationStyle();
/**
* 設置定位資源
*/
aMap.setLocationSource(this);
aMap.setMyLocationEnabled(true);
// aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
aMap.moveCamera(CameraUpdateFactory.zoomTo(16));
first_hud = KProgressHUD.create(AddRoute2Activity.this)
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
.setCancellable(false)
.setAnimationSpeed(2)
.setDimAmount(0.5f)
.show();
/**
* 設置地圖加載完成回調
*/
aMap.setOnMapLoadedListener(new AMap.OnMapLoadedListener() {
@Override
public void onMapLoaded() {
// aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
/**
* 設置縮放級別爲16
*/
aMap.moveCamera(CameraUpdateFactory.zoomTo(16));
aMap.showMapText(true);
aMap.showIndoorMap(false);
// 重新加載地圖數據。
// aMap.setLoadOfflineData(true);
}
});
//移動地圖
aMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
if (currentShowPoint == 0) {
img_current_position.setImageResource(R.mipmap.select_position_g_up);
txt_down.setVisibility(View.GONE);
txt_up.setVisibility(View.GONE);
} else if (0 < currentShowPoint && currentShowPoint < 17) {
img_current_position.setImageResource(R.mipmap.select_position_y_up);
txt_up.setVisibility(View.VISIBLE);
txt_up.setText(currentShowPoint+"");
txt_down.setVisibility(View.GONE);
} else if (currentShowPoint == 17) {
img_current_position.setImageResource(R.mipmap.select_position_r_up);
txt_down.setVisibility(View.GONE);
txt_up.setVisibility(View.GONE);
}
}
@Override
public void onCameraChangeFinish(CameraPosition cameraPosition) {
if (currentShowPoint == 0) {
img_current_position.setImageResource(R.mipmap.select_position_g_down);
txt_down.setVisibility(View.GONE);
txt_up.setVisibility(View.GONE);
} else if (0 < currentShowPoint && currentShowPoint < 17) {
img_current_position.setImageResource(R.mipmap.select_position_y_down);
txt_down.setVisibility(View.VISIBLE);
txt_down.setText(currentShowPoint+"");
txt_up.setVisibility(View.GONE);
} else if (currentShowPoint == 17) {
img_current_position.setImageResource(R.mipmap.select_position_r_down);
txt_down.setVisibility(View.GONE);
txt_up.setVisibility(View.GONE);
}
// 獲取當前地圖中心點的座標
mTarget = aMap.getCameraPosition().target;
//準確位置獲取
geocodeSearch = new GeocodeSearch(AddRoute2Activity.this);
geocodeSearch.setOnGeocodeSearchListener(AddRoute2Activity.this);
latLonPoint = new LatLonPoint(mTarget.latitude, mTarget.longitude);
getAddress(latLonPoint);
//第一次定位移動到定位點作爲地圖的中心點
if (isShowMoveLocationCenter == true) {
aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
isShowMoveLocationCenter = false;
}
if (isShowVisibleArea == true) {
//設置顯示的範圍
setShowVisibleArea();
}
}
});
}
/**
* 自定義定位圖標
*/
private void setMyLocationStyle() {
MyLocationStyle myLocationStyle = new MyLocationStyle();// 自定義系統定位小藍點
myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.mipmap.o_map));// 設置小藍點的圖標
myLocationStyle.strokeColor(Color.TRANSPARENT);// 設置圓形的邊框顏色
myLocationStyle.radiusFillColor(Color.TRANSPARENT);// 設置圓形的填充顏色
myLocationStyle.anchor(0.5f, 0.5f);// 設置小藍點的錨點
myLocationStyle.strokeWidth(0);// 設置圓形的邊框粗細
aMap.setMyLocationStyle(myLocationStyle);
}
private void initFindView() {
txt_add_route = (TextView) findViewById(R.id.txt_add_route);
//移動到當前定位點
img_map_location_type_locate = (ImageView) findViewById(R.id.img_map_location_type_locate);
img_current_position = (ImageView) findViewById(R.id.img_current_position);
img_current_position.setImageResource(R.mipmap.select_position_g_down);
txt_down= (TextView) findViewById(R.id.txt_down);
txt_up= (TextView) findViewById(R.id.txt_up);
edt_search_via_point = (EditText) findViewById(R.id.edt_search_via_point);
txt_my_route = (TextView) findViewById(R.id.txt_my_route);
listView = (ListView) findViewById(R.id.listView);
}
private void listenerView() {
//點擊選擇 設置當前的位置給點
img_current_position.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//設置起始位置
if (currentShowPoint == 0) {
// currentShowPoint = 17;
if (routePointModelArrayList.size() >= 1) {
routePointModelArrayList.remove(0);
routePointModelArrayList.add(0, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
currentShowPoint = 1;
} else {
routePointModelArrayList.add(new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
currentShowPoint = 17;
}
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
if (startMark == null) {
startMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_start_up)));
startMark.setAnchor(0.5f, 0.5f);
} else {
startMark.setPosition(mTarget);
}
}
//結束點
else if (currentShowPoint == 17) {
if (routePointModelArrayList.size() == 18) {
currentShowPoint = 17;
routePointModelArrayList.remove(17);
routePointModelArrayList.add(17, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
} else if (routePointModelArrayList.size() >= 2) {
currentShowPoint = 1;
routePointModelArrayList.remove(routePointModelArrayList.size() - 1);
routePointModelArrayList.add(new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
} else {
currentShowPoint = 1;
routePointModelArrayList.add(new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
}
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
if (endMark == null) {
endMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_end_up)));
endMark.setAnchor(0.5f, 0.5f);
} else {
endMark.setPosition(mTarget);
}
}
//途徑點1
else if (currentShowPoint == 1) {
currentShowPoint = 2;
if (routePointModelArrayList.size() >= 3) {
routePointModelArrayList.remove(1);
}
routePointModelArrayList.add(1, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaOneMark == null) {
// viaOneMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaOneMark.setAnchor(0.5f, 0.5f);
// } else {
// viaOneMark.setPosition(mTarget);
// }
}
// 途徑點2
else if (currentShowPoint == 2) {
currentShowPoint = 3;
if (routePointModelArrayList.size() >= 4) {
routePointModelArrayList.remove(2);
}
routePointModelArrayList.add(2, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaTwoMark == null) {
// viaTwoMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_02_up)));
// viaTwoMark.setAnchor(0.5f, 0.5f);
// } else {
// viaTwoMark.setPosition(mTarget);
// }
}
// 途徑點3
else if (currentShowPoint == 3) {
currentShowPoint = 4;
if (routePointModelArrayList.size() >= 5) {
routePointModelArrayList.remove(3);
}
routePointModelArrayList.add(3, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaThereMark == null) {
// viaThereMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_03_up)));
// viaThereMark.setAnchor(0.5f, 0.5f);
// } else {
// viaThereMark.setPosition(mTarget);
// }
}
// 途徑點4
else if (currentShowPoint == 4) {
currentShowPoint = 5;
if (routePointModelArrayList.size() >= 6) {
routePointModelArrayList.remove(4);
}
routePointModelArrayList.add(4, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaFourMark == null) {
// viaFourMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaFourMark.setAnchor(0.5f, 0.5f);
// } else {
// viaFourMark.setPosition(mTarget);
// }
}
// 途徑點5
else if (currentShowPoint == 5) {
currentShowPoint = 6;
if (routePointModelArrayList.size() >= 7) {
routePointModelArrayList.remove(5);
}
routePointModelArrayList.add(5, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaFiveMark == null) {
// viaFiveMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaFiveMark.setAnchor(0.5f, 0.5f);
// } else {
// viaFiveMark.setPosition(mTarget);
// }
}
// 途徑點6
else if (currentShowPoint == 6) {
currentShowPoint = 7;
if (routePointModelArrayList.size() >= 8) {
routePointModelArrayList.remove(6);
}
routePointModelArrayList.add(6, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaSixMark == null) {
// viaSixMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaSixMark.setAnchor(0.5f, 0.5f);
// } else {
// viaSixMark.setPosition(mTarget);
// }
}
// 途徑點7
else if (currentShowPoint == 7) {
currentShowPoint = 8;
if (routePointModelArrayList.size() >= 9) {
routePointModelArrayList.remove(7);
}
routePointModelArrayList.add(7, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaSevenMark == null) {
// viaSevenMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaSevenMark.setAnchor(0.5f, 0.5f);
// } else {
// viaSevenMark.setPosition(mTarget);
// }
}
// 途徑點8
else if (currentShowPoint == 8) {
currentShowPoint = 9;
if (routePointModelArrayList.size() >= 10) {
routePointModelArrayList.remove(8);
}
routePointModelArrayList.add(8, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaEightMark == null) {
// viaEightMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaEightMark.setAnchor(0.5f, 0.5f);
// } else {
// viaEightMark.setPosition(mTarget);
// }
}
// 途徑點9
else if (currentShowPoint == 9) {
currentShowPoint = 10;
if (routePointModelArrayList.size() >= 11) {
routePointModelArrayList.remove(9);
}
routePointModelArrayList.add(9, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaNineMark == null) {
// viaNineMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaNineMark.setAnchor(0.5f, 0.5f);
// } else {
// viaNineMark.setPosition(mTarget);
// }
}
// 途徑點10
else if (currentShowPoint == 10) {
currentShowPoint = 11;
if (routePointModelArrayList.size() >= 12) {
routePointModelArrayList.remove(10);
}
routePointModelArrayList.add(10, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaTenMark == null) {
// viaTenMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaTenMark.setAnchor(0.5f, 0.5f);
// } else {
// viaTenMark.setPosition(mTarget);
// }
}
// 途徑點11
else if (currentShowPoint == 11) {
currentShowPoint = 12;
if (routePointModelArrayList.size() >= 13) {
routePointModelArrayList.remove(11);
}
routePointModelArrayList.add(11, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaElevenMark == null) {
// viaElevenMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaElevenMark.setAnchor(0.5f, 0.5f);
// } else {
// viaElevenMark.setPosition(mTarget);
// }
}
// 途徑點12
else if (currentShowPoint == 12) {
currentShowPoint = 13;
if (routePointModelArrayList.size() >= 14) {
routePointModelArrayList.remove(12);
}
routePointModelArrayList.add(12, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaTwelveMark == null) {
// viaTwelveMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaTwelveMark.setAnchor(0.5f, 0.5f);
// } else {
// viaTwelveMark.setPosition(mTarget);
// }
}
// 途徑點13
else if (currentShowPoint == 13) {
currentShowPoint = 14;
if (routePointModelArrayList.size() >= 15) {
routePointModelArrayList.remove(13);
}
routePointModelArrayList.add(13, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaThirteenMark == null) {
// viaThirteenMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaThirteenMark.setAnchor(0.5f, 0.5f);
// } else {
// viaThirteenMark.setPosition(mTarget);
// }
}
// 途徑點14
else if (currentShowPoint == 14) {
currentShowPoint = 15;
if (routePointModelArrayList.size() >= 16) {
routePointModelArrayList.remove(14);
}
routePointModelArrayList.add(14, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaFourteenMark == null) {
// viaFourteenMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaFourteenMark.setAnchor(0.5f, 0.5f);
// } else {
// viaFourteenMark.setPosition(mTarget);
// }
}
// 途徑點15
else if (currentShowPoint == 15) {
currentShowPoint = 16;
if (routePointModelArrayList.size() >= 17) {
routePointModelArrayList.remove(15);
}
routePointModelArrayList.add(15, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaFifteenMark == null) {
// viaFifteenMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaFifteenMark.setAnchor(0.5f, 0.5f);
// } else {
// viaFifteenMark.setPosition(mTarget);
// }
}
// 途徑點16
else if (currentShowPoint == 16) {
currentShowPoint = 17;
if (routePointModelArrayList.size() >= 18) {
routePointModelArrayList.remove(16);
}
routePointModelArrayList.add(16, new RoutePointModel(mTarget.latitude, mTarget.longitude, currentSpecificPosition));
// listView.setSelection(routePointModelArrayList.size() - 5);
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.requestFocusFromTouch();
listView.setSelection(routePointModelArrayList.size() - 5);
}
},500);
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
//畫點
// if (viaSixteenMark == null) {
// viaSixteenMark = aMap.addMarker(new MarkerOptions().position(mTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_01_up)));
// viaSixteenMark.setAnchor(0.5f, 0.5f);
// } else {
// viaSixteenMark.setPosition(mTarget);
// }
// currentShowPoint = 17;
}
//點擊確認後設置新的中心點顯示的圖標
if (currentShowPoint == 0) {
img_current_position.setImageResource(R.mipmap.select_position_g_down);
txt_down.setVisibility(View.GONE);
txt_up.setVisibility(View.GONE);
} else if (0 < currentShowPoint && currentShowPoint < 17) {
img_current_position.setImageResource(R.mipmap.select_position_y_down);
txt_down.setVisibility(View.VISIBLE);
txt_down.setText(currentShowPoint+"");
txt_up.setVisibility(View.GONE);
} else if (currentShowPoint == 17) {
img_current_position.setImageResource(R.mipmap.select_position_r_down);
txt_down.setVisibility(View.GONE);
txt_up.setVisibility(View.GONE);
}
// //當結束點和開始點都有值得時候就執行劃線的方法
setLatLonPointToMap(routePointModelArrayList);
}
});
//創建約跑的item點擊事件
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//點擊選中了那一項 那一項 就處於編輯狀態
if (routePointModelArrayList == null) {
currentShowPoint = position;
} else if (0 < routePointModelArrayList.size() && routePointModelArrayList.size() < 18) {
if (position == routePointModelArrayList.size()) {
currentShowPoint = 17;
} else {
currentShowPoint = position;
}
} else if (routePointModelArrayList.size() == 18) {
currentShowPoint = position;
}
//刷新 當前選中的顏色改變
viaAdapter.notifyDataSetChanged();
//移動到選中的點處
if (routePointModelArrayList == null) {
} else if (routePointModelArrayList.size() > 0) {
LatLng viaLatLng = null;
if (routePointModelArrayList.size() == 1) {
if (position == 0) {
viaLatLng = new LatLng(routePointModelArrayList.get(position).getLatitude(),
routePointModelArrayList.get(position).getLongitude());
//設置地圖中心點
aMap.moveCamera(CameraUpdateFactory.changeLatLng(viaLatLng));
isShowVisibleArea = false;
} else {
//點擊的另外
}
} else if (routePointModelArrayList.size() > 1 && routePointModelArrayList.size() < 18) {
if (position == routePointModelArrayList.size()) {// 0 1 2 2
viaLatLng = new LatLng(routePointModelArrayList.get(position - 1).getLatitude(),
routePointModelArrayList.get(position - 1).getLongitude());
//設置地圖中心點
aMap.moveCamera(CameraUpdateFactory.changeLatLng(viaLatLng));
isShowVisibleArea = false;
} else if (position == routePointModelArrayList.size() - 1) {
} else {
viaLatLng = new LatLng(routePointModelArrayList.get(position).getLatitude(),
routePointModelArrayList.get(position).getLongitude());
//設置地圖中心點
aMap.moveCamera(CameraUpdateFactory.changeLatLng(viaLatLng));
isShowVisibleArea = false;
}
} else if (routePointModelArrayList.size() == 18) {
viaLatLng = new LatLng(routePointModelArrayList.get(position).getLatitude(),
routePointModelArrayList.get(position).getLongitude());
//設置地圖中心點
aMap.moveCamera(CameraUpdateFactory.changeLatLng(viaLatLng));
isShowVisibleArea = false;
}
}
}
});
//返回
findViewById(R.id.img_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(AddRoute2Activity.this);
builder.setTitle("提示");
builder.setMessage("退出此次編輯");
builder.setPositiveButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNegativeButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (isEdit == true) {
//返回上一界面 然後繼續返回到我的路書界面
Intent intent = new Intent();
setResult(EDIT_ROUTE_FINISH_FOR_RESULT, intent);
}
finish();
}
});
builder.show();
}
});
findViewById(R.id.txt_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(AddRoute2Activity.this);
builder.setTitle("提示");
builder.setMessage("退出此次編輯");
builder.setPositiveButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNegativeButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (isEdit == true) {
//返回上一界面 然後繼續返回到我的路書界面
Intent intent = new Intent();
setResult(EDIT_ROUTE_FINISH_FOR_RESULT, intent);
}
finish();
}
});
builder.show();
}
});
//移動到定位點
img_map_location_type_locate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
isShowVisibleArea = false;
}
});
aMap.setOnMapTouchListener(new AMap.OnMapTouchListener() {
@Override
public void onTouch(MotionEvent motionEvent) {
isShowVisibleArea = false;
// img_current_position.setVisibility(View.VISIBLE);
img_map_location_type_locate.setVisibility(View.VISIBLE);
}
});
//搜索
edt_search_via_point.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(AddRoute2Activity.this, SearchViaPointActivity.class);
intent.putExtra("currentShowPoint", currentShowPoint);
startActivityForResult(intent, SEARCH_VIA_POINT);
}
});
//完成提交
txt_add_route.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (routePointModelArrayList != null && routePointModelArrayList.size() >= 2) {
hud = KProgressHUD.create(AddRoute2Activity.this)
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
.setCancellable(false)
.setAnimationSpeed(1)
.setDimAmount(0.5f)
.show();
// //當結束點和開始點都有值得時候就執行劃線的方法
// setLatLonPointToMap(latLonPointList);
//設置顯示區域
setShowVisibleArea();
//定位點 設置定位層是否顯示。
aMap.setMyLocationEnabled(false);
new Thread(new Runnable() {
@Override
public void run() {
SystemClock.sleep(2000);
runOnUiThread(new Runnable() {
@Override
public void run() {
getMapPhoto();
}
});
}
}).start();
// getMapPhoto();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(AddRoute2Activity.this);
builder.setTitle("提示");
builder.setMessage("請選擇開始點和結束點");
builder.setNegativeButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.show();
}
}
});
}
//設置顯示區域
private void setShowVisibleArea() {
//設置顯示區域
if (routePointModelArrayList != null && routePointModelArrayList.size() >= 2) {
LatLngBounds bounds = null;
// for (int i = 0; i < routePointModelArrayList.size(); i++) {
// bounds = new LatLngBounds.Builder()
// .include(new LatLng(routePointModelArrayList.get(i).getLatitude(),
// routePointModelArrayList.get(i).getLongitude())).build();
// }
if (routePointModelArrayList.size() == 2) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 3) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 4) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 5) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 6) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 7) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 8) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 9) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(8).getLatitude(),
routePointModelArrayList.get(8).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 10) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(8).getLatitude(),
routePointModelArrayList.get(8).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(9).getLatitude(),
routePointModelArrayList.get(9).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 11) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(8).getLatitude(),
routePointModelArrayList.get(8).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(9).getLatitude(),
routePointModelArrayList.get(9).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(10).getLatitude(),
routePointModelArrayList.get(10).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 12) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(8).getLatitude(),
routePointModelArrayList.get(8).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(9).getLatitude(),
routePointModelArrayList.get(9).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(10).getLatitude(),
routePointModelArrayList.get(10).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(11).getLatitude(),
routePointModelArrayList.get(11).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 13) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(8).getLatitude(),
routePointModelArrayList.get(8).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(9).getLatitude(),
routePointModelArrayList.get(9).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(10).getLatitude(),
routePointModelArrayList.get(10).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(11).getLatitude(),
routePointModelArrayList.get(11).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(12).getLatitude(),
routePointModelArrayList.get(12).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 14) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(8).getLatitude(),
routePointModelArrayList.get(8).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(9).getLatitude(),
routePointModelArrayList.get(9).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(10).getLatitude(),
routePointModelArrayList.get(10).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(11).getLatitude(),
routePointModelArrayList.get(11).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(12).getLatitude(),
routePointModelArrayList.get(12).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(13).getLatitude(),
routePointModelArrayList.get(13).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 15) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(8).getLatitude(),
routePointModelArrayList.get(8).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(9).getLatitude(),
routePointModelArrayList.get(9).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(10).getLatitude(),
routePointModelArrayList.get(10).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(11).getLatitude(),
routePointModelArrayList.get(11).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(12).getLatitude(),
routePointModelArrayList.get(12).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(13).getLatitude(),
routePointModelArrayList.get(13).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(14).getLatitude(),
routePointModelArrayList.get(14).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 16) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(8).getLatitude(),
routePointModelArrayList.get(8).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(9).getLatitude(),
routePointModelArrayList.get(9).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(10).getLatitude(),
routePointModelArrayList.get(10).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(11).getLatitude(),
routePointModelArrayList.get(11).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(12).getLatitude(),
routePointModelArrayList.get(12).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(13).getLatitude(),
routePointModelArrayList.get(13).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(14).getLatitude(),
routePointModelArrayList.get(14).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(15).getLatitude(),
routePointModelArrayList.get(15).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 17) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(8).getLatitude(),
routePointModelArrayList.get(8).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(9).getLatitude(),
routePointModelArrayList.get(9).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(10).getLatitude(),
routePointModelArrayList.get(10).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(11).getLatitude(),
routePointModelArrayList.get(11).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(12).getLatitude(),
routePointModelArrayList.get(12).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(13).getLatitude(),
routePointModelArrayList.get(13).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(14).getLatitude(),
routePointModelArrayList.get(14).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(15).getLatitude(),
routePointModelArrayList.get(15).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(16).getLatitude(),
routePointModelArrayList.get(16).getLongitude()))
.build();
} else if (routePointModelArrayList.size() == 18) {
bounds = new LatLngBounds.Builder()
.include(new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(1).getLatitude(),
routePointModelArrayList.get(1).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(2).getLatitude(),
routePointModelArrayList.get(2).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(3).getLatitude(),
routePointModelArrayList.get(3).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(4).getLatitude(),
routePointModelArrayList.get(4).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(5).getLatitude(),
routePointModelArrayList.get(5).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(6).getLatitude(),
routePointModelArrayList.get(6).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(7).getLatitude(),
routePointModelArrayList.get(7).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(8).getLatitude(),
routePointModelArrayList.get(8).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(9).getLatitude(),
routePointModelArrayList.get(9).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(10).getLatitude(),
routePointModelArrayList.get(10).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(11).getLatitude(),
routePointModelArrayList.get(11).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(12).getLatitude(),
routePointModelArrayList.get(12).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(13).getLatitude(),
routePointModelArrayList.get(13).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(14).getLatitude(),
routePointModelArrayList.get(14).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(15).getLatitude(),
routePointModelArrayList.get(15).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(16).getLatitude(),
routePointModelArrayList.get(16).getLongitude()))
.include(new LatLng(routePointModelArrayList.get(17).getLatitude(),
routePointModelArrayList.get(17).getLongitude()))
.build();
}
aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, mapView.getWidth(), mapView.getHeight(), PixelOrdpManager.dip2px(getBaseContext(), 100)));
}
}
//提交數據
private void commitRouteData() {
routeModel.setUserid(LoginManager.userid);
routeModel.setMileage(mileage);
Gson gson = new Gson();
routeModel.setDatajson(gson.toJson(routePointModelArrayList));
routeModel.setImgurl(imgUrl);
if (isEdit == false) {
//添加新路書
RouteManager.getInstance().addRoute(routeModel, new MBCallback.MBValueCallBack<RouteModel>() {
@Override
public void onSuccess(RouteModel result) {
// Log.d("AddRouteActivity", "result:" + result);
// Toast.makeText(AddRouteActivity.this, "result:" + result, Toast.LENGTH_SHORT).show();
//照片提交成功後刪除截圖照片
if (!TextUtils.isEmpty(imgUrl)) {
File file = new File(imgUrl);
if (file.exists())
file.delete();
}
hud.dismiss();
Toast.makeText(AddRoute2Activity.this, "新路書提交成功", Toast.LENGTH_SHORT).show();
finish();
}
@Override
public void onError(String code) {
// Log.d("AddRouteActivity", code);
// Toast.makeText(AddRoute2Activity.this, code, Toast.LENGTH_SHORT).show();
hud.dismiss();
Toast.makeText(AddRoute2Activity.this, "提交路書失敗請稍後重試", Toast.LENGTH_SHORT).show();
}
@Override
public void onFinished() {
}
});
} else if (isEdit == true) {
//修改路書 routeModel需要設置id
RouteManager.getInstance().updateRoute(routeModel, new MBCallback.MBValueCallBack<RouteModel>() {
@Override
public void onSuccess(RouteModel result) {
//照片提交成功後刪除截圖照片
if (!TextUtils.isEmpty(imgUrl)) {
File file = new File(imgUrl);
if (file.exists())
file.delete();
}
hud.dismiss();
Toast.makeText(AddRoute2Activity.this, "編輯路書成功", Toast.LENGTH_SHORT).show();
//返回上一界面 然後繼續返回到我的路書界面
Intent intent = new Intent();
setResult(EDIT_ROUTE_FINISH_FOR_RESULT, intent);
finish();
}
@Override
public void onError(String code) {
hud.dismiss();
Toast.makeText(AddRoute2Activity.this, "提交路書失敗請稍後重試", Toast.LENGTH_SHORT).show();
}
@Override
public void onFinished() {
}
});
}
}
//設置數據進行劃線
private void setLatLonPointToMap(ArrayList<RoutePointModel> routePointList) {
if (routePointList != null) {
LatLng startTarget = null;
LatLng endTarget = null;
if (latLonPointList != null) {
latLonPointList.clear();
}
if (routePointList.size() == 1) {
startTarget = new LatLng(routePointList.get(0).getLatitude(), routePointList.get(0).getLongitude());
} else if (routePointList.size() == 2) {
startTarget = new LatLng(routePointList.get(0).getLatitude(), routePointList.get(0).getLongitude());
endTarget = new LatLng(routePointList.get(1).getLatitude(), routePointList.get(1).getLongitude());
} else if (routePointList.size() > 2) {
startTarget = new LatLng(routePointList.get(0).getLatitude(), routePointList.get(0).getLongitude());
endTarget = new LatLng(routePointList.get(routePointList.size() - 1).getLatitude(), routePointList.get(routePointList.size() - 1).getLongitude());
for (int i = 1; i < routePointList.size(); i++) {
latLonPointList.add(new LatLonPoint(routePointList.get(i).getLatitude(), routePointList.get(i).getLongitude()));
}
}
// 當結束點和開始點都有值得時候就執行劃線的方法
if (startTarget != null && endTarget != null) {
showProgressDialog();
routeSearch = new RouteSearch(AddRoute2Activity.this);
routeSearch.setRouteSearchListener(AddRoute2Activity.this);
// fromAndTo包含路徑規劃的起點和終點,drivingMode表示駕車模式
// 第三個參數表示途經點(最多支持16個),第四個參數表示避讓區域(最多支持32個),第五個參數表示避讓道路
// RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, drivingMode, null, null, "");
if (latLonPointList != null) {
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(new RouteSearch.FromAndTo(
new LatLonPoint(startTarget.latitude, startTarget.longitude),
new LatLonPoint(endTarget.latitude, endTarget.longitude)),
RouteSearch.DrivingDefault, latLonPointList, null, "");
routeSearch.calculateDriveRouteAsyn(query);
} else {
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(new RouteSearch.FromAndTo(
new LatLonPoint(startTarget.latitude, startTarget.longitude),
new LatLonPoint(endTarget.latitude, endTarget.longitude)),
RouteSearch.DrivingDefault, null, null, "");
routeSearch.calculateDriveRouteAsyn(query);
}
} else {
//當沒有開始點和結束點時清除線路 重現畫點
aMap.clear();
//畫點
if (startTarget != null) {
startMark = aMap.addMarker(new MarkerOptions().position(startTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_start_up)));
startMark.setAnchor(0.5f, 0.5f);
}
}
}
}
private void loadTheData() {
viaAdapter = new ViaAdapter(AddRoute2Activity.this);
listView.setAdapter(viaAdapter);
viaAdapter.notifyDataSetChanged();
//編輯界面
intent = getIntent();
if (intent.getSerializableExtra("routeModel") != null) {
routeModel = (RouteModel) intent.getSerializableExtra("routeModel");
//判斷是否是編輯
isEdit = true;
routeModel.setRouteid(routeModel.getRouteid());
txt_my_route.setText("編輯路書");
//解析
String routeString = routeModel.getDatajson();
routePointModelArrayList = new Gson().fromJson(routeString, new TypeToken<ArrayList<RoutePointModel>>() {
}.getType());
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
setLatLonPointToMap(routePointModelArrayList);
//判斷顯示幾個途經點
// if (routeSize == 2) {
// currentStartPosition = routePointModelArrayList.get(0).getTitle();
// currentEndPosition = routePointModelArrayList.get(1).getTitle();
//
// startTarget = new LatLng(routePointModelArrayList.get(0).getLatitude(), routePointModelArrayList.get(0).getLongitude());
// endTarget = new LatLng(routePointModelArrayList.get(1).getLatitude(), routePointModelArrayList.get(1).getLongitude());
//
// txt_route_start.setText(currentStartPosition);
// txt_route_end.setText(currentEndPosition);
//
// } else if (routeSize == 3) {
// currentStartPosition = routePointModelArrayList.get(0).getTitle();
// currentViaOnePosition = routePointModelArrayList.get(1).getTitle();
// currentEndPosition = routePointModelArrayList.get(2).getTitle();
//
// startTarget = new LatLng(routePointModelArrayList.get(0).getLatitude(), routePointModelArrayList.get(0).getLongitude());
// viaOneTarget = new LatLng(routePointModelArrayList.get(1).getLatitude(), routePointModelArrayList.get(1).getLongitude());
// endTarget = new LatLng(routePointModelArrayList.get(2).getLatitude(), routePointModelArrayList.get(2).getLongitude());
//
// //途經點1 顯示
// layout_route_via_one.setVisibility(View.VISIBLE);
// layout_route_add.setVisibility(View.GONE);
// //結束點 顯示添加途經點按鈕
// img_route_end.setVisibility(View.GONE);
// layout_route_end_add.setVisibility(View.VISIBLE);
//
//
// txt_route_start.setText(currentStartPosition);
// txt_route_via_one.setText(currentViaOnePosition);
// txt_route_end.setText(currentEndPosition);
//
// latLonPointList.add(0, new LatLonPoint(routePointModelArrayList.get(1).getLatitude(), routePointModelArrayList.get(1).getLongitude()));
// } else if (routeSize == 4) {
// currentStartPosition = routePointModelArrayList.get(0).getTitle();
// currentViaOnePosition = routePointModelArrayList.get(1).getTitle();
// currentViaTwoPosition = routePointModelArrayList.get(2).getTitle();
// currentEndPosition = routePointModelArrayList.get(3).getTitle();
//
// startTarget = new LatLng(routePointModelArrayList.get(0).getLatitude(), routePointModelArrayList.get(0).getLongitude());
// viaOneTarget = new LatLng(routePointModelArrayList.get(1).getLatitude(), routePointModelArrayList.get(1).getLongitude());
// viaTwoTarget = new LatLng(routePointModelArrayList.get(2).getLatitude(), routePointModelArrayList.get(2).getLongitude());
// endTarget = new LatLng(routePointModelArrayList.get(3).getLatitude(), routePointModelArrayList.get(3).getLongitude());
//
// layout_route_via_one.setVisibility(View.VISIBLE);
// layout_route_via_two.setVisibility(View.VISIBLE);
// layout_route_add.setVisibility(View.GONE);
// //結束點 顯示添加途經點按鈕
// img_route_end.setVisibility(View.GONE);
// layout_route_end_add.setVisibility(View.VISIBLE);
//
//
// txt_route_start.setText(currentStartPosition);
// txt_route_via_one.setText(currentViaOnePosition);
// txt_route_via_two.setText(currentViaTwoPosition);
// txt_route_end.setText(currentEndPosition);
//
// latLonPointList.add(0, new LatLonPoint(routePointModelArrayList.get(1).getLatitude(), routePointModelArrayList.get(1).getLongitude()));
// latLonPointList.add(1, new LatLonPoint(routePointModelArrayList.get(2).getLatitude(), routePointModelArrayList.get(2).getLongitude()));
// } else if (routeSize == 5) {
// currentStartPosition = routePointModelArrayList.get(0).getTitle();
// currentViaOnePosition = routePointModelArrayList.get(1).getTitle();
// currentViaTwoPosition = routePointModelArrayList.get(2).getTitle();
// currentViaTherePosition = routePointModelArrayList.get(3).getTitle();
// currentEndPosition = routePointModelArrayList.get(4).getTitle();
//
// startTarget = new LatLng(routePointModelArrayList.get(0).getLatitude(), routePointModelArrayList.get(0).getLongitude());
// viaOneTarget = new LatLng(routePointModelArrayList.get(1).getLatitude(), routePointModelArrayList.get(1).getLongitude());
// viaTwoTarget = new LatLng(routePointModelArrayList.get(2).getLatitude(), routePointModelArrayList.get(2).getLongitude());
// viaThereTarget = new LatLng(routePointModelArrayList.get(3).getLatitude(), routePointModelArrayList.get(3).getLongitude());
// endTarget = new LatLng(routePointModelArrayList.get(4).getLatitude(), routePointModelArrayList.get(4).getLongitude());
//
// layout_route_via_one.setVisibility(View.VISIBLE);
// layout_route_via_two.setVisibility(View.VISIBLE);
// layout_route_via_there.setVisibility(View.VISIBLE);
//
// layout_route_end_add.setVisibility(View.GONE);
// img_route_end.setVisibility(View.VISIBLE);
// layout_route_add.setVisibility(View.GONE);
//
// txt_route_start.setText(currentStartPosition);
// txt_route_via_one.setText(currentViaOnePosition);
// txt_route_via_two.setText(currentViaTwoPosition);
// txt_route_via_there.setText(currentViaTherePosition);
// txt_route_end.setText(currentEndPosition);
//
// latLonPointList.add(0, new LatLonPoint(routePointModelArrayList.get(1).getLatitude(), routePointModelArrayList.get(1).getLongitude()));
// latLonPointList.add(1, new LatLonPoint(routePointModelArrayList.get(2).getLatitude(), routePointModelArrayList.get(2).getLongitude()));
// latLonPointList.add(2, new LatLonPoint(routePointModelArrayList.get(3).getLatitude(), routePointModelArrayList.get(3).getLongitude()));
// }
//當結束點和開始點都有值得時候就執行劃線的方法
// setLatLonPointToMap(latLonPointList);
}
}
private void initBroadcaseReciver() {
}
@Override
public void activate(OnLocationChangedListener onLocationChangedListener) {
mListener = onLocationChangedListener;
if (mLocationClient == null) {
mLocationClient = new AMapLocationClient(MBUtil.getContext());
AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
mLocationClient.setLocationListener(this);
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
mLocationClient.setLocationOption(mLocationOption);
mLocationClient.startLocation();
}
}
@Override
public void deactivate() {
mListener = null;
if (mLocationClient != null) {
mLocationClient.stopLocation();
mLocationClient.onDestroy();
}
mLocationClient = null;
}
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (mListener != null && aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
mListener.onLocationChanged(aMapLocation);// 顯示系統藍點
latitude = aMapLocation.getLatitude();// 緯度
longitude = aMapLocation.getLongitude();// 經度
// TODO: 2016/6/2
} else {
String errText = "定位失敗," + aMapLocation.getErrorCode() + ": " + aMapLocation.getErrorInfo();
System.out.println(errText);
}
} else {
}
}
/**
* 逆地理編碼
*/
public void getAddress(final LatLonPoint latLonPoint) {
RegeocodeQuery regeocodeQuery = new RegeocodeQuery(latLonPoint, 200, GeocodeSearch.AMAP);
geocodeSearch.getFromLocationAsyn(regeocodeQuery);
}
@Override
public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
if (rCode == 1000) {
if (result != null && result.getRegeocodeAddress() != null && result.getRegeocodeAddress().getFormatAddress() != null) {
first_hud.dismiss();
//當前具體位置
currentSpecificPosition = result.getRegeocodeAddress().getFormatAddress();
// 如果是activityforresult來進行數據設置
if (isShowActivityForResult == true) {
isShowActivityForResult = false;
//當結束點和開始點都有值得時候就執行劃線的方法
// setLatLonPointToMap(routePointModelArrayList);
}
} else {
Toast.makeText(AddRoute2Activity.this, "定位失敗,請重試", Toast.LENGTH_SHORT);
}
} else if (rCode == 27) {
Toast.makeText(AddRoute2Activity.this, "定位失敗,請重試", Toast.LENGTH_SHORT);
} else if (rCode == 32) {
Toast.makeText(AddRoute2Activity.this, "定位失敗,請重試", Toast.LENGTH_SHORT);
} else {
Toast.makeText(AddRoute2Activity.this, "定位失敗,請重試", Toast.LENGTH_SHORT);
}
}
@Override
public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
}
@Override
public void onBusRouteSearched(BusRouteResult busRouteResult, int i) {
}
@Override
public void onDriveRouteSearched(DriveRouteResult result, int errorCode) {
isShowVisibleArea = true;
aMap.clear();
if (errorCode == 1000) {
if (result != null && result.getPaths() != null) {
if (result.getPaths().size() > 0) {
mDriveRouteResult = result;
// for (int i = 0; i < result.getPaths().size(); i++) {
final DrivePath drivePath = mDriveRouteResult.getPaths().get(0);
MyDrivingRouteOverlay drivingRouteOverlay = new MyDrivingRouteOverlay(this, aMap, drivePath,
mDriveRouteResult.getStartPos(),
mDriveRouteResult.getTargetPos());
//距離
double totalDistance = 0;
for (DrivePath drivePaths : result.getPaths()) {
if (drivePaths != null && drivePaths.getSteps() != null) {
for (DriveStep driveStep : drivePaths.getSteps()) {
totalDistance += driveStep.getDistance();
}
}
}
mileage = (long) totalDistance;
drivingRouteOverlay.removeFromMap();
drivingRouteOverlay.setNodeIconVisibility(false);//去除車圖標
drivingRouteOverlay.addToMap();
drivingRouteOverlay.zoomToSpan();
if (routePointModelArrayList.size() > 2) {
for (int i = 1; i < routePointModelArrayList.size() - 1; i++) {
double latitude = routePointModelArrayList.get(i).getLatitude();
double longitude = routePointModelArrayList.get(i).getLongitude();
String title = routePointModelArrayList.get(i).getTitle();
//自定義設置顯示的圖標
View view = LayoutInflater.from(this).inflate(R.layout.inflate_route_maker, null);
TextView txt_maker_num = (TextView) view.findViewById(R.id.txt_maker_num);
if (latitude > 0 && longitude > 0) {
txt_maker_num.setText(i + "");
MarkerOptions markerOptions = new MarkerOptions();
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromView(view);
markerOptions.icon(bitmapDescriptor).position(new LatLng(latitude, longitude));
Marker marker = aMap.addMarker(markerOptions);
viaMakerMap.put(title, marker);
}
}
}
// 獲取當前地圖開始點座標
LatLng startTarget = new LatLng(routePointModelArrayList.get(0).getLatitude(),
routePointModelArrayList.get(0).getLongitude()
);
// 獲取當前地圖結束點座標
LatLng endTarget = new LatLng(routePointModelArrayList.get(routePointModelArrayList.size() - 1).getLatitude(),
routePointModelArrayList.get(routePointModelArrayList.size() - 1).getLongitude()
);
LatLngBounds bounds = new LatLngBounds.Builder()
.include(startTarget).include(endTarget).build();
aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, PixelOrdpManager.dip2px(getBaseContext(), 100)));
} else if (result != null && result.getPaths() == null) {
ToastUtil.show(AddRoute2Activity.this, "對不起,沒有搜索到相關數據!");
}
} else {
ToastUtil.show(AddRoute2Activity.this, "對不起,沒有搜索到相關數據!");
}
} else {
ToastUtil.show(AddRoute2Activity.this, "對不起,沒有搜索到相關數據!");
}
dissmissProgressDialog();
}
/**
* 處理圖片
*
* @param bm 所要轉換的bitmap
* @param newWidth
* @param newHeight
* @return 指定寬高的bitmap
*/
public static Bitmap zoomImg(Bitmap bm, int newWidth, int newHeight) {
// 獲得圖片的寬高
int width = bm.getWidth();
int height = bm.getHeight();
// 計算縮放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要縮放的matrix參數
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的圖片
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
return newbm;
}
@Override
public void onWalkRouteSearched(WalkRouteResult walkRouteResult, int i) {
}
//路書照片的存儲
private void getMapPhoto() {
// img_current_position.setVisibility(View.GONE);
img_map_location_type_locate.setVisibility(View.GONE);
// 設置截屏監聽接口,截取地圖可視區域
aMap.getMapScreenShot(new AMap.OnMapScreenShotListener() {
@Override
public void onMapScreenShot(Bitmap bitmap) {
}
@Override
public void onMapScreenShot(Bitmap bitmap, int arg1) {
Bitmap currentBitmap = zoomImg(bitmap, PixelOrdpManager.dip2px(getBaseContext(), 375), PixelOrdpManager.dip2px(getBaseContext(), 300));
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
imgUrl = Environment.getExternalStorageDirectory() + "/motoband_" + sdf.format(new Date()) + ".png";
try {
// 保存在SD卡根目錄下,圖片爲png格式。
// FileOutputStream fos = new FileOutputStream(
// Environment.getExternalStorageDirectory() + "/test_"
// + sdf.format(new Date()) + ".png");
FileOutputStream fos = new FileOutputStream(imgUrl);
// boolean b = currentBitmap.compress(Bitmap.CompressFormat.PNG, 80, fos);
// boolean b = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
boolean b = currentBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
try {
fos.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
//得到照片URL在上傳
commitRouteData();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
});
}
//DrivingRouteOverlay,自定義開始點 和結束點
private class MyDrivingRouteOverlay extends DrivingRouteOverlay {
public MyDrivingRouteOverlay(Context context, AMap aMap, DrivePath drivePath, LatLonPoint latLonPoint, LatLonPoint latLonPoint1) {
super(context, aMap, drivePath, latLonPoint, latLonPoint1);
}
// @Override
// protected void addStartAndEndMarker() {
//// super.addStartAndEndMarker();//這方法如果寫這個super就會有本身自帶的開始點和結束點 如果不寫沒有線路
// startMark = aMap.addMarker(new MarkerOptions().position(startTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_start)));
// endMark = aMap.addMarker(new MarkerOptions().position(endTarget).icon(BitmapDescriptorFactory.fromResource(R.mipmap.position_end)));
// startMark.showInfoWindow();
// endMarker.showInfoWindow();
// }
//設置開始點
protected BitmapDescriptor getStartBitmapDescriptor() {
return BitmapDescriptorFactory.fromResource(R.mipmap.position_start);
}
//設置結束點
protected BitmapDescriptor getEndBitmapDescriptor() {
return BitmapDescriptorFactory.fromResource(R.mipmap.position_end);
}
}
/**
* 顯示進度框
*/
private void showProgressDialog() {
if (progDialog == null)
progDialog = new ProgressDialog(this);
progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDialog.setIndeterminate(false);
progDialog.setCancelable(true);
progDialog.setMessage("正在搜索");
progDialog.show();
}
/**
* 隱藏進度框
*/
private void dissmissProgressDialog() {
if (progDialog != null) {
progDialog.dismiss();
}
}
private class ViaAdapter extends BaseAdapter {
private ArrayList<RoutePointModel> routePointModelList;
private Context mcontext;
private ViaAdapter(Context context) {
mcontext = context;
}
public void setData(ArrayList<RoutePointModel> data) {
if (routePointModelList == null) {
routePointModelList = new ArrayList<RoutePointModel>();
}
routePointModelList.clear();
if (data != null) {
routePointModelList.addAll(data);
}
// notifyDataSetChanged();
}
@Override
public int getCount() {
if (routePointModelList == null) {
return 1;
} else if (routePointModelList.size() >= 18) {
return 18;
} else {
return routePointModelList.size() + 1;
}
}
@Override
public RoutePointModel getItem(int position) {
return routePointModelList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViaViewHolder viaViewHolder;
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.inflate_add_route, parent, false);
viaViewHolder = new ViaViewHolder();
viaViewHolder.layout_roate_via = (LinearLayout) convertView.findViewById(R.id.layout_roate_via);
viaViewHolder.txt_route_via = (TextView) convertView.findViewById(R.id.txt_route_via);
viaViewHolder.txt_via = (TextView) convertView.findViewById(R.id.txt_via);
convertView.setTag(viaViewHolder);
} else {
viaViewHolder = (ViaViewHolder) convertView.getTag();
}
//設置當前哪一個被選中
if (currentShowPoint == position) {
viaViewHolder.txt_route_via.setTextColor(0xFFFFFFFF);
} else {
if (currentShowPoint == 17 && position == routePointModelList.size()) {
viaViewHolder.txt_route_via.setTextColor(0xFFFFFFFF);
} else {
viaViewHolder.txt_route_via.setTextColor(0xFF828282);
}
}
//開始點 途經點 結束點顯示的圖標
if (routePointModelList != null && routePointModelList.size() > 0) {
if (position == 0) {//0
//綠色
viaViewHolder.txt_via.setTextColor(0xFF00FF00);
viaViewHolder.txt_via.setText("起");
} else if (0 < position && position < routePointModelList.size() && position < 17) {
//黃色 1 - 數據總數的
viaViewHolder.txt_via.setTextColor(0xFFFFCE00);
viaViewHolder.txt_via.setText(position + "");
} else if (position == routePointModelList.size()) {
//紅色
viaViewHolder.txt_via.setTextColor(0xFFDC143C);
viaViewHolder.txt_via.setText("終");
viaViewHolder.txt_route_via.setText("選擇結束點");
} else if (position == 17 && routePointModelList.size() == 18) {
//紅色
viaViewHolder.txt_via.setTextColor(0xFFDC143C);
viaViewHolder.txt_via.setText("終");
viaViewHolder.txt_route_via.setText("選擇結束點");
}
} else {
//綠色
viaViewHolder.txt_via.setTextColor(0xFF00FF00);
viaViewHolder.txt_via.setText("起");
}
//設置數據
//路書實體有數據時才設置數據,沒有數據設置默認
if (routePointModelList != null && routePointModelList.size() > 0) {
//0 //開始點 途經點
if (position < routePointModelList.size()) { //0 1 2 3 3
RoutePointModel routePointModel = routePointModelList.get(position);
if (position == 0) {
viaViewHolder.txt_route_via.setText(routePointModel.getTitle());
} else if (position > 0 && position < routePointModelList.size() - 1) {//2 3
if (position < routePointModelList.size() - 1) {
viaViewHolder.txt_route_via.setText(routePointModel.getTitle());
} else if (position == routePointModelList.size() - 2) {
viaViewHolder.txt_route_via.setText("選擇途經點" + position);
}
} else if (position == routePointModelList.size() - 1 && routePointModelList.size() < 18) {
viaViewHolder.txt_route_via.setText("選擇途經點" + position);
} else if (position == routePointModelList.size() - 1 && routePointModelList.size() == 18) {
viaViewHolder.txt_route_via.setText(routePointModel.getTitle());
}
} else {
//途經點設置默認顯示的 終點設置顯示數據
if (0 < position && position < routePointModelList.size()) {
viaViewHolder.txt_route_via.setText("選擇途經點" + position);
} else if (position == routePointModelList.size() && routePointModelList.size() >= 2) {
RoutePointModel routePointModel = routePointModelList.get(position - 1);
viaViewHolder.txt_route_via.setText(routePointModel.getTitle());
}
}
} else {
viaViewHolder.txt_route_via.setText("添加開始點");
}
//刪除開始點 途經點 結束點的按鈕
viaViewHolder.layout_roate_via.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//刪除點 要保證裏面有可以刪除的點
if (routePointModelArrayList != null && routePointModelArrayList.size() > 0) {
if (position == 0) {
routePointModelArrayList.remove(position);
//重新繪製地圖
setLatLonPointToMap(routePointModelArrayList);
} else if (0 < position && position < routePointModelArrayList.size() - 1) {//0 1 2 2
routePointModelArrayList.remove(position);
//重新繪製地圖
setLatLonPointToMap(routePointModelArrayList);
} else if (position == routePointModelArrayList.size() - 1) {
//當點的集合等於18時,集合滿了,可以移除當前的一項,要不然這一項爲空,不做處理
if (routePointModelArrayList.size() == 18) {
routePointModelArrayList.remove(position);
//重新繪製地圖
setLatLonPointToMap(routePointModelArrayList);
}
} else if (position == routePointModelArrayList.size()) {
if (1 < routePointModelArrayList.size() && routePointModelArrayList.size() < 18) {
routePointModelArrayList.remove(position - 1);
//重新繪製地圖
setLatLonPointToMap(routePointModelArrayList);
} else if (routePointModelArrayList.size() == 18) {
routePointModelArrayList.remove(position);
//重新繪製地圖
setLatLonPointToMap(routePointModelArrayList);
}
}
}
//刪除數據後,再次顯示下一個誰被選中
if (routePointModelArrayList != null && routePointModelArrayList.size() > 0) {
//只有開始點時/點都滿的時候
if (routePointModelArrayList.size() == 18 || routePointModelArrayList.size() == 1) {
currentShowPoint = 17;
} else if (routePointModelArrayList.size() < 18) {
currentShowPoint = routePointModelArrayList.size() - 1;
}
} else {
currentShowPoint = 0;
}
viaAdapter.setData(routePointModelArrayList);
viaAdapter.notifyDataSetChanged();
}
});
// else {
// if (position == 0) {
// viaViewHolder.txt_route_via.setText("選擇開始點");
// } else if (0<position&&position<routePointModelList.size()-1) {
// viaViewHolder.txt_route_via.setText("選擇途經點"+position);
// }else if(position==routePointModelList.size()-1){
// viaViewHolder.txt_route_via.setText("選擇結束點");
// }
// }
return convertView;
}
private class ViaViewHolder {
LinearLayout layout_roate_via;
TextView txt_via;
TextView txt_route_via;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SEARCH_VIA_POINT) {
if (resultCode == SEARCH_VIA_POINT_FOR_RESULT) {
Tip tip = data.getParcelableExtra("tip");
int currentPosition = data.getIntExtra("currentShowPoint", 1);
currentShowPoint = currentPosition;
if (tip != null) {
if (tip.getPoint() != null) {
aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(tip.getPoint().getLatitude(), tip.getPoint().getLongitude())));
isShowActivityForResult = true;
} else {
if (currentPosition == 1) {
Toast.makeText(this, "請選擇準確開始點", Toast.LENGTH_SHORT).show();
} else if (currentPosition == 5) {
Toast.makeText(this, "請選擇準確結束點", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "請選擇準確途徑點", Toast.LENGTH_SHORT).show();
}
}
}
}
}
}
/**
* 方法必須重寫
*/
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
/**
* 方法必須重寫
*/
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
/**
* 方法必須重寫
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
/**
* 方法必須重寫
*/
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
deactivate();
}
}
裏面涉及到實體類RouteModel
package com.motoband.core.model;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import java.io.Serializable;
/**
* 路書
* Created by Administrator on 2016/6/2.
*/
@DatabaseTable(tableName = "Route")
public class RouteModel implements Serializable {
@DatabaseField(columnName = "routeid", id = true)
private String routeid;// 路書ID
@DatabaseField(columnName = "title")
private String title;// 標題
@DatabaseField(columnName = "userid")
private String userid;// 用戶ID
@DatabaseField(columnName = "imgurl")
private String imgurl;// 圖片URL
@DatabaseField(columnName = "datajson")
private String datajson;// 數據
@DatabaseField(columnName = "mileage")
private long mileage;// 里程
@DatabaseField(columnName = "addtime")
private long addtime;// 添加時間
public RouteModel() {
}
public RouteModel(String routeid, String title, String userid, String imgurl, String datajson, long mileage, long addtime) {
this.routeid = routeid;
this.title = title;
this.userid = userid;
this.imgurl = imgurl;
this.datajson = datajson;
this.mileage = mileage;
this.addtime = addtime;
}
public String getRouteid() {
return routeid;
}
public void setRouteid(String routeid) {
this.routeid = routeid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getImgurl() {
return imgurl;
}
public void setImgurl(String imgurl) {
this.imgurl = imgurl;
}
public String getDatajson() {
return datajson;
}
public void setDatajson(String datajson) {
this.datajson = datajson;
}
public long getMileage() {
return mileage;
}
public void setMileage(long mileage) {
this.mileage = mileage;
}
public long getAddtime() {
return addtime;
}
public void setAddtime(long addtime) {
this.addtime = addtime;
}
@Override
public String toString() {
return "RouteModel{" +
"routeid='" + routeid + '\'' +
", title='" + title + '\'' +
", userid='" + userid + '\'' +
", imgurl='" + imgurl + '\'' +
", datajson='" + datajson + '\'' +
", mileage=" + mileage +
", addtime=" + addtime +
'}';
}
}
裏面涉及到上傳 修改路徑規劃的管理類,根據自己項目的需求去設計。
裏面涉及到的搜索位置的界面xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearlayout_main"
android:background="@color/M323535"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.motoband.ui.activity.SearchViaPointActivity">
<!--//搜索-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="58dp"
android:background="@color/M4A4D4F"
android:orientation="horizontal">
<com.motoband.ui.view.MyEditText
android:id="@+id/txt_select_city_search"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/dp10"
android:layout_marginEnd="@dimen/dp70"
android:layout_marginLeft="@dimen/dp10"
android:layout_marginRight="@dimen/dp70"
android:layout_marginStart="@dimen/dp10"
android:layout_marginTop="@dimen/dp10"
android:background="@drawable/shape_white"
android:bufferType="editable"
android:ellipsize="end"
android:gravity="center|start"
android:hint="@string/txt_search"
android:imeOptions="actionSearch"
android:inputType="text"
android:paddingEnd="@dimen/dp36"
android:paddingLeft="@dimen/dp10"
android:paddingRight="@dimen/dp36"
android:paddingStart="@dimen/dp10"
android:singleLine="true"
android:textColor="@color/MFFFFFF"
android:textColorHint="@color/MC8C8C8"
android:textCursorDrawable="@drawable/shape_cursor_color"
android:textSize="@dimen/sp16"
/>
<LinearLayout
android:id="@+id/layout_delete"
android:layout_width="@dimen/dp50"
android:layout_height="@dimen/dp50"
android:layout_alignEnd="@+id/txt_select_city_search"
android:layout_alignRight="@+id/txt_select_city_search"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone">
<ImageView
android:id="@+id/img_delete_telephone"
android:layout_width="@dimen/dp16"
android:layout_height="@dimen/dp16"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/dp24"
android:layout_marginStart="@dimen/dp24"
android:background="@mipmap/nember_button_del_2"
android:contentDescription="@null" />
</LinearLayout>
<!--//取消-->
<TextView
android:id="@+id/txt_cancel"
android:layout_width="@dimen/dp70"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="@string/camera_cancel"
android:textColor="@color/MA3A3A3"
android:textSize="@dimen/sp16"
/>
</RelativeLayout>
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:divider="@null" />
</LinearLayout>
搜索位置的activity:
package com.motoband.ui.activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.amap.api.services.help.Inputtips;
import com.amap.api.services.help.InputtipsQuery;
import com.amap.api.services.help.Tip;
import com.motoband.R;
import com.motoband.ui.manager.SoftKeyboardManager;
import com.motoband.ui.manager.StatusBarManager;
import com.motoband.ui.view.MyEditText;
import com.umeng.analytics.MobclickAgent;
import java.util.ArrayList;
import java.util.List;
public class SearchViaPointActivity extends AppCompatActivity implements Inputtips.InputtipsListener{
//搜索
private MyEditText txt_search_rally_point;
//刪除按鈕
private LinearLayout layout_delete;
private Context context;
private ListView listView;
//位置的適配器
private ChooseLocationAdapter chooseLocationAdapter;
List<Tip> tipList;
private int currentShowPoint;
private Intent intent;
public static final int SEARCH_VIA_POINT_FOR_RESULT = 165;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_via_point);
//狀態欄顏色的設置
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearlayout_main);
StatusBarManager.SetStatusBar(getWindow(), this, getResources(), "#323535", linearLayout);
context = getBaseContext();
initView();
initData();
initListener();
}
private void initView() {
//搜索
txt_search_rally_point = (MyEditText) findViewById(R.id.txt_select_city_search);
//刪除
layout_delete = (LinearLayout) findViewById(R.id.layout_delete);
listView = (ListView) findViewById(R.id.listview);
chooseLocationAdapter = new ChooseLocationAdapter(this);
}
private void initData() {
intent=getIntent();
currentShowPoint=intent.getIntExtra("currentShowPoint",1);
}
private void initListener() {
//返回
findViewById(R.id.txt_cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SoftKeyboardManager.HideSoftKeyboard(v);
finish();
}
});
//搜索
txt_search_rally_point.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String newText = s.toString().trim();
if (newText != null) {
InputtipsQuery inputquery = new InputtipsQuery(newText, txt_search_rally_point.getText().toString());
Inputtips inputTips = new Inputtips(SearchViaPointActivity.this, inputquery);
inputTips.setInputtipsListener(SearchViaPointActivity.this);
inputTips.requestInputtipsAsyn();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
//點擊選擇集結點返回選擇集結點
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Tip tip=tipList.get(position);
Intent intent=new Intent();
intent.putExtra("tip",tip);
intent.putExtra("currentShowPoint",currentShowPoint);
setResult(SEARCH_VIA_POINT_FOR_RESULT,intent);
SoftKeyboardManager.HideSoftKeyboard(view);
finish();
}
});
}
@Override
public void onGetInputtips(List<Tip> tipList, int rCode) {
if (rCode == 1000) {// 正確返回
this.tipList=tipList;
listView.setAdapter(chooseLocationAdapter);
chooseLocationAdapter.setData(tipList);
chooseLocationAdapter.notifyDataSetChanged();
// List<String> listString = new ArrayList<String>();
// for (int i = 0; i < tipList.size(); i++) {
// listString.add(tipList.get(i).getName());
// }
// ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(
// getApplicationContext(),
// R.layout.route_inputs, listString);
// searchText.setAdapter(aAdapter);
// aAdapter.notifyDataSetChanged();
} else {
// ToastUtil.showerror(this, rCode);
}
}
public class ChooseLocationAdapter extends BaseAdapter {
private Context mcontext;
ArrayList<Tip> poiItemList = new ArrayList<Tip>();
public ChooseLocationAdapter(Context context) {
mcontext = context;
}
//數據操作方法
public void setData(List<Tip> data) {
if (data != null) {
poiItemList = (ArrayList<Tip>) data;
}
}
@Override
public int getCount() {
return poiItemList.size();
}
@Override
public Tip getItem(int position) {
return poiItemList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ChooseLocationViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getBaseContext()).inflate(R.layout.inflate_choose_location, parent, false);
holder = new ChooseLocationViewHolder();
holder.layout_choose_location = (LinearLayout) convertView.findViewById(R.id.layout_choose_location);
holder.txt_location_detail = (TextView) convertView.findViewById(R.id.txt_location_detail);
holder.txt_location = (TextView) convertView.findViewById(R.id.tv_location);
convertView.setTag(holder);
} else {
holder = (ChooseLocationViewHolder) convertView.getTag();
}
//設置數據
Tip tip = poiItemList.get(position);
//店名
holder.txt_location_detail.setText(tip.getName());
//具體位置 北京市 朝陽區 街道
holder.txt_location.setText(tip.getDistrict());
// holder.txt_location.setText(tip.getName()
// + "" + tip.getAdcode()
// + "" + tip.getDistrict()
// + "" + tip.getPoiID()
// + "" + tip.getPoint()
// );
return convertView;
}
public class ChooseLocationViewHolder {
private LinearLayout layout_choose_location;
//具體位置
private TextView txt_location_detail;
//附近
private TextView txt_location;
}
}
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);
}
}
裏面涉及到的關於路徑規劃那塊的業務邏輯比較繞,多去想幾遍,就能寫出很好的路徑規劃了,另外不得不吐槽一下的就是Android的gps定位,由於手機製造商的硬件設施參差不齊,導致有的手機依靠gps定位很困難,期待Android的統一,讓手機的gps牛起來。