├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── debug_zeus.keystore ├── libs │ ├── AMap_Location_V3.0.0_20160922.jar │ ├── AMap_Search_V3.6.1_20161122.jar │ └── Android_Map3D_SDK_V4.1.3_20161208.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── pk │ │ └── com │ │ └── lib │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── pk │ │ │ └── com │ │ │ └── lib │ │ │ ├── BusinessFragment.java │ │ │ ├── CommonMapFunction.java │ │ │ ├── MainActivity.java │ │ │ └── map │ │ │ ├── AnimationCallBack.java │ │ │ ├── MapCenterChangeListener.java │ │ │ ├── MapControl.java │ │ │ ├── MapFrament.java │ │ │ ├── MapFramentFactory.java │ │ │ ├── MapHelper.java │ │ │ ├── MapResource.java │ │ │ ├── MapUtil.java │ │ │ ├── NaviCallBack.java │ │ │ ├── OnMapClickCallback.java │ │ │ ├── OnMapLoaded.java │ │ │ ├── OnMarkerOnclickListener.java │ │ │ ├── OnPKMapTouch.java │ │ │ ├── amp │ │ │ ├── AMapHelper.java │ │ │ └── AmapFragment.java │ │ │ ├── control │ │ │ ├── AMapControl.java │ │ │ └── IControl.java │ │ │ ├── modle │ │ │ ├── PKContainer.java │ │ │ ├── PKEquipmentMarkerHolder.java │ │ │ ├── PKEuipmentInfo.java │ │ │ ├── PKLatLng.java │ │ │ ├── PKListLatLngContainer.java │ │ │ ├── PKListTraceLocationContainer.java │ │ │ ├── PKMarker.java │ │ │ ├── PKMarkerHolder.java │ │ │ ├── PKMarkerOptions.java │ │ │ ├── PKTrace.java │ │ │ └── PKTraceLocation.java │ │ │ ├── navi │ │ │ ├── AMapNavi.java │ │ │ └── INavi.java │ │ │ ├── overlay │ │ │ ├── AMapOverLay.java │ │ │ └── IOverLay.java │ │ │ ├── smooth │ │ │ ├── AMapSooth.java │ │ │ ├── ISmooth.java │ │ │ └── PKSmoothListener.java │ │ │ └── trace │ │ │ ├── AMapTrace.java │ │ │ ├── ITrace.java │ │ │ └── PKTraceListener.java │ ├── jniLibs │ │ ├── arm64-v8a │ │ │ ├── libgdinamapv4sdk752.so │ │ │ └── libgdinamapv4sdk752ex.so │ │ └── armeabi │ │ │ ├── libgdinamapv4sdk752.so │ │ │ └── libgdinamapv4sdk752ex.so │ └── res │ │ ├── drawable-xhdpi │ │ ├── btn_car_location_bkg.9.png │ │ ├── btn_car_location_exception.png │ │ ├── btn_car_location_exception_pressed.png │ │ ├── btn_car_location_moving.png │ │ ├── btn_car_location_moving_pressed.png │ │ ├── btn_car_location_parking.png │ │ ├── btn_car_location_parking_pressed.png │ │ ├── icon_car.png │ │ └── icon_end.png │ │ ├── drawable │ │ ├── btn_car_exception_press.xml │ │ ├── btn_car_moving_press.xml │ │ └── btn_car_parking_press.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_business.xml │ │ ├── fragment_gaode_map.xml │ │ └── item_marker_car.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── pk │ └── com │ └── lib │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | MapLibForApp -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MapLibForApp 2 | 如今出行类的App越来越常见,更多的应用将地图Sdk嵌入到自己的App中去,以实现基本的功能,如定位,路径规划,标注,导航等等。 3 | 4 | 今天我要分享的是Android一种通用的地图类解耦架构,将地图与业务解耦,上层的Fragment通过接口调用底层MapFragment实现地图的基础操作。 5 | 6 | 具体的实现类图如下图: 7 | 8 | 整体的架构大概可以分为三层: 9 | 第一层:地图结构抽象层 主要是地图的功能抽象,定义地图与外部交互的接口。 10 | 11 | CommonMapFunction:定义了地图与顶层业务的交互接口,例如addMarker,searchRout,startNavi等等。 12 | 13 | MapFragment:地图功能的抽象工具类,抽象地图的常见功能,关联MapHelper实现地图功能与具体地图Sdk的解耦。 14 | 15 | MapHelper: 地图Sdk的具体载体,将地图功能抽象成五大块,分别是平滑移动(ISoomth),导航(INavi),覆盖物(IOverlay),控制(IControl),轨迹纠偏(ITrace),并且定义相关的接口底层相应的Sdk实现。 16 | MapControl:实现地图MapFragment和BusinessFragment的交互,由Activity实现 通过getMapController返回一个实现了CommonFunction全部接口的地图实例Fragment对象, 17 | 第二层 :底层Sdk的具体地图功能实现。 18 | 19 | 主要是使用地图sdk实现地图的各种业务功能,如打点标注,导航等等。 20 | 第三层:对用户可见展示层 21 | 22 | MainActivity:加载地图的具体活动窗口页面,将地图MapFragment置于底层,业务的BusinessFragment置于地图上方。实现了MapControl接口,通过getMapController返回一个实现了CommonMapFunction的地图实例。主要代码如下: 23 | public class ZeusMonitorActivity extends BaseActivity implements MapControl { 24 | 25 | public final static String FRAGMENT_TAG_MAP = "mapFragment"; 26 | public final static String FRAGMENT_TAG_BUSSINESS = "bussinessFragment"; 27 | 28 | MapFrament mapFrament = null; 29 | ZeusMornitorFragment mZeusMornitorFragment = null; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | setFullScreen(); 34 | super.onCreate(savedInstanceState); 35 | mTitleView.setVisibility(View.GONE); 36 | final FragmentManager fragmentManager = getSupportFragmentManager(); 37 | mapFrament = (MapFrament) fragmentManager.findFragmentByTag(FRAGMENT_TAG_MAP); 38 | if (mapFrament == null) { 39 | mapFrament = MapFramentFactory.createMapFrament(MapFramentFactory.GAODE_MAP_CODE, new Bundle()); 40 | fragmentManager.beginTransaction() 41 | .add(R.id.map_container, mapFrament, FRAGMENT_TAG_MAP) 42 | .commit(); 43 | } 44 | new Handler().postAtTime(new Runnable() { 45 | @Override 46 | public void run() { 47 | mZeusMornitorFragment = (ZeusMornitorFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG_BUSSINESS); 48 | if (mZeusMornitorFragment == null) { 49 | mZeusMornitorFragment = ZeusMornitorFragment.getInstance(getIntent().getExtras()); 50 | fragmentManager.beginTransaction() 51 | .add(R.id.fragment_container, mZeusMornitorFragment, FRAGMENT_TAG_BUSSINESS) 52 | .commit(); 53 | } 54 | } 55 | }, 200); 56 | } 57 | @Override 58 | @Override 59 | public CommonMapFunction getMapController() { 60 | return mapFrament; 61 | } 62 | } 63 | 64 | AmapFragment:地图的具体实例,本文高德地图,实现了继承自MapFragment,实现了CommonFunction的全部接口,并且在MainActivity中通过接口MapControl的getMapController返回。 65 | BusinessFragment:覆盖在地图上面的界面展示,与服务端或者是其它的页面进行通信,然后操作地图实现相应的功能。通过getContext获取MainActivity的实例并强转成MapControl对象通过getMapController获取地图操作的实例对象。代码如下: 66 | @Override 67 | public void onAttach(Context context) { 68 | super.onAttach(context); 69 | if (context instanceof MapControl) { 70 | mapController = (MapControl) context; 71 | } 72 | private void otherMethod(){ 73 | mapController.getMapController().setOnFiveMapTouchListener(this); 74 | } 75 | 76 | 最后提出几点需要注意的地方: 77 | 一. 开发过程中注意坐标系的转换,国测局,百度地图,高德地图,用的不是同一个坐标系,在需要转化使用时,需要一定的转换,参见demo里的MapUtil类。 78 | 二. 在初始化地图时,如果需要立马在地图进行操作如打一个点之类的,因为BusinessFragment和AMapFragment是并行运行的,因此可能打点的时候地图尚未加载完成,这时候要引入缓存队列, 79 | 比如AddMarker的时候要先判断地图是否加载完成,没有则将数据存入一个缓存队列里,然后在onMapLoaded的回调里去将缓存里的数据恢复操作到地图上。 80 | 81 | 82 | @Override 83 | public void onMapLoaded() { 84 | 85 | isMapReady = true; 86 | 87 | showMyLoactionMarker(); 88 | 89 | // 显示因为地图没有加载成功时添加到缓存的数据 90 | 91 | gotoMyLocation(); 92 | 93 | addMarkerByMarkerHolder(); 94 | 95 | } 96 | 97 | } 98 | 99 | @Override 100 | 101 | public void addCarStateMarker(FiveLatLng fiveLatLng, String title, int status, int pistionStyle) { 102 | 103 | if (isMapReady) { 104 | 105 | FiveMarker fiveMarker = mapHelper.getmIOverLay().addMarker(fiveLatLng, inflatCarStausView(title, status)); 106 | 107 | } else { 108 | 109 | currentCarMarkerHolder = new MarkerHolder(fiveLatLng, title, status); 110 | 111 | } 112 | 113 | } 114 | 115 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | applicationId "pk.com.lib" 9 | minSdkVersion 16 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | signingConfigs { 21 | debug { 22 | keyAlias 'android' 23 | keyPassword '123456' 24 | storeFile file('debug_zeus.keystore') 25 | storePassword '123456' 26 | } 27 | } 28 | } 29 | 30 | dependencies { 31 | compile fileTree(dir: 'libs', include: ['*.jar']) 32 | testCompile 'junit:junit:4.12' 33 | compile 'com.android.support:appcompat-v7:25.2.0' 34 | } 35 | -------------------------------------------------------------------------------- /app/debug_zeus.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/debug_zeus.keystore -------------------------------------------------------------------------------- /app/libs/AMap_Location_V3.0.0_20160922.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/libs/AMap_Location_V3.0.0_20160922.jar -------------------------------------------------------------------------------- /app/libs/AMap_Search_V3.6.1_20161122.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/libs/AMap_Search_V3.6.1_20161122.jar -------------------------------------------------------------------------------- /app/libs/Android_Map3D_SDK_V4.1.3_20161208.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/libs/Android_Map3D_SDK_V4.1.3_20161208.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/pukai/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/pk/com/lib/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/BusinessFragment.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Button; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | import pk.com.lib.map.MapControl; 16 | import pk.com.lib.map.modle.PKLatLng; 17 | 18 | 19 | /** 20 | * Created by pukai on 17/3/16. 21 | */ 22 | public class BusinessFragment extends Fragment implements View.OnClickListener { 23 | private static BusinessFragment mBusinessFragment; 24 | private MapControl mMapControl; 25 | 26 | //button 27 | private Button mAddMarkerBtn; 28 | private Button mDrawLineBtn; 29 | private Button mMoveMapBtn; 30 | private Button mDrawRoutBtn; 31 | private Button mNaviBtn; 32 | private Button mSmoothBtn; 33 | private Button mClearMapBtn; 34 | private Button mQuitBtn; 35 | 36 | @Override 37 | public void onAttach(Context context) { 38 | super.onAttach(context); 39 | if (context instanceof MapControl) { 40 | mMapControl = (MapControl) context; 41 | } 42 | } 43 | 44 | public BusinessFragment() { 45 | } 46 | 47 | public static BusinessFragment getInstance(Bundle bundle) { 48 | if (mBusinessFragment == null) { 49 | mBusinessFragment = new BusinessFragment(); 50 | mBusinessFragment.setArguments(bundle); 51 | } 52 | return mBusinessFragment; 53 | } 54 | 55 | @Nullable 56 | @Override 57 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 58 | View view = inflater.inflate(R.layout.fragment_business, container, false); 59 | initView(view); 60 | setOnClickListener(); 61 | return view; 62 | } 63 | 64 | private void initView(View view) { 65 | mAddMarkerBtn = (Button) view.findViewById(R.id.fragment_business_add_marker_btn); 66 | mDrawLineBtn = (Button) view.findViewById(R.id.fragment_business_draw_line_btn); 67 | mMoveMapBtn = (Button) view.findViewById(R.id.fragment_business_move_map_btn); 68 | mDrawRoutBtn = (Button) view.findViewById(R.id.fragment_business_draw_rout_btn); 69 | mNaviBtn = (Button) view.findViewById(R.id.fragment_business_navi_btn); 70 | mSmoothBtn = (Button) view.findViewById(R.id.fragment_business_smooth_move_btn); 71 | mClearMapBtn = (Button) view.findViewById(R.id.fragment_business_clear_btn); 72 | mQuitBtn = (Button) view.findViewById(R.id.fragment_business_cancle_btn); 73 | } 74 | 75 | private void setOnClickListener() { 76 | mAddMarkerBtn.setOnClickListener(this); 77 | mDrawLineBtn.setOnClickListener(this); 78 | mMoveMapBtn.setOnClickListener(this); 79 | mDrawRoutBtn.setOnClickListener(this); 80 | mNaviBtn.setOnClickListener(this); 81 | mSmoothBtn.setOnClickListener(this); 82 | mClearMapBtn.setOnClickListener(this); 83 | mQuitBtn.setOnClickListener(this); 84 | } 85 | 86 | @Override 87 | public void onClick(View v) { 88 | switch (v.getId()) { 89 | case R.id.fragment_business_add_marker_btn: 90 | mMapControl.getMapController().addBusinessMarker(new PKLatLng(31.2393627086, 121.4995369338), "东方明珠塔"); 91 | break; 92 | case R.id.fragment_business_draw_line_btn: 93 | mMapControl.getMapController().addPollyLine(getTestData()); 94 | break; 95 | case R.id.fragment_business_move_map_btn: 96 | List fiveLatLngList = new ArrayList<>(); 97 | fiveLatLngList.add(new PKLatLng(31.2363627086, 121.4995369338)); 98 | fiveLatLngList.add(new PKLatLng(31.2423627086, 121.4995369338)); 99 | mMapControl.getMapController().moveMap(fiveLatLngList); 100 | break; 101 | case R.id.fragment_business_draw_rout_btn: 102 | break; 103 | case R.id.fragment_business_navi_btn: 104 | break; 105 | case R.id.fragment_business_smooth_move_btn: 106 | break; 107 | case R.id.fragment_business_clear_btn: 108 | break; 109 | case R.id.fragment_business_cancle_btn: 110 | break; 111 | 112 | } 113 | } 114 | 115 | private List getTestData() { 116 | List fiveLatLngList = new ArrayList<>(); 117 | for (int i = 0; i < 30; i++) { 118 | PKLatLng fiveLatLng = new PKLatLng(31.2393627086 - i * 0.01, 121.4995369338 - i * 0.01); 119 | fiveLatLngList.add(fiveLatLng); 120 | } 121 | return fiveLatLngList; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/CommonMapFunction.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib; 2 | 3 | import java.util.List; 4 | 5 | import pk.com.lib.map.modle.PKLatLng; 6 | 7 | /** 8 | * Created by pukai on 16/12/19. 9 | */ 10 | public interface CommonMapFunction { 11 | void setMapCenter(PKLatLng fiveLatLng); 12 | 13 | void addBusinessMarker(PKLatLng fiveLatLng, String title); 14 | 15 | void addPollyLine(List fiveLatLngList); 16 | 17 | void moveMap(List fiveLatLngList); 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/MainActivity.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib; 2 | 3 | import android.os.Handler; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | 8 | import pk.com.lib.map.MapControl; 9 | import pk.com.lib.map.MapFrament; 10 | import pk.com.lib.map.MapFramentFactory; 11 | 12 | public class MainActivity extends AppCompatActivity implements MapControl { 13 | 14 | 15 | public final static String FRAGMENT_TAG_MAP = "mapFragment"; 16 | public final static String FRAGMENT_TAG_BUSSINESS = "bussinessFragment"; 17 | 18 | MapFrament mapFrament = null; 19 | BusinessFragment mBusinessFragment = null; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | final FragmentManager fragmentManager = getSupportFragmentManager(); 26 | mapFrament = (MapFrament) fragmentManager.findFragmentByTag(FRAGMENT_TAG_MAP); 27 | if (mapFrament == null) { 28 | mapFrament = MapFramentFactory.createMapFrament(MapFramentFactory.AMAP_MAP_CODE, new Bundle()); 29 | fragmentManager.beginTransaction() 30 | .add(R.id.map_container, mapFrament, FRAGMENT_TAG_MAP) 31 | .commit(); 32 | } 33 | new Handler().postAtTime(new Runnable() { 34 | @Override 35 | public void run() { 36 | mBusinessFragment = (BusinessFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG_BUSSINESS); 37 | if (mBusinessFragment == null) { 38 | mBusinessFragment = BusinessFragment.getInstance(getIntent().getExtras()); 39 | fragmentManager.beginTransaction() 40 | .add(R.id.fragment_container, mBusinessFragment, FRAGMENT_TAG_BUSSINESS) 41 | .commit(); 42 | } 43 | } 44 | }, 200); 45 | } 46 | 47 | @Override 48 | public CommonMapFunction getMapController() { 49 | return mapFrament; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/AnimationCallBack.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | /** 4 | * Created by pukai on 2016-4-26. 5 | * 6 | * 公共的地图动画回调接口 7 | */ 8 | public interface AnimationCallBack { 9 | /** 10 | * 动画完成后的回调事件 11 | */ 12 | void animationFinish(); 13 | 14 | /** 15 | * 动画关闭事件 16 | */ 17 | void onCancel(); 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/MapCenterChangeListener.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | /** 4 | * Created by pukai on 17/2/16. 5 | */ 6 | public interface MapCenterChangeListener { 7 | void startChange(); 8 | 9 | void finishChange(); 10 | } -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/MapControl.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | import pk.com.lib.CommonMapFunction; 4 | 5 | /** 6 | * Created by pukai on 17/2/9. 7 | */ 8 | public interface MapControl { 9 | CommonMapFunction getMapController(); 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/MapFrament.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import pk.com.lib.CommonMapFunction; 11 | import pk.com.lib.map.smooth.PKSmoothListener; 12 | 13 | 14 | /** 15 | * Created by pukai on 2016-4-26. 16 | *

17 | * 基础地图Fragment 18 | */ 19 | public abstract class MapFrament extends Fragment implements CommonMapFunction { 20 | /** 21 | * 当前地图的状态 22 | */ 23 | protected static final int REAL_LOCATION = 0; 24 | protected static final int EQUIPMENT_DETAIL = 1; 25 | protected static final int TRACE_PLAYBACK = 2; 26 | 27 | /** 28 | * 当前的模式 29 | *

  • 10 车辆
  • 30 | *
  • 11 用户
  • 31 | *
  • 12 自由模式
  • 32 | */ 33 | public static final int CAR_STYLE = 10; 34 | public static final int USER_STYLE = 11; 35 | public static final int FREEDOM_STYLE = 12; 36 | 37 | protected int currentMapStatus; 38 | 39 | protected OnMapClickCallback onMapClickCallback = null; 40 | protected OnMapLoaded onMapLoadedListener = null; 41 | protected OnMarkerOnclickListener mOnMarkerOnclickListener; 42 | protected OnPKMapTouch mOnPKMapTouch; 43 | protected PKSmoothListener mPKSmoothListener; 44 | /** 45 | * 当前的地图的显示模式 46 | *
  • 10 车辆
  • 47 | *
  • 11 个人
  • 48 | *
  • 12 自由
  • 49 | */ 50 | protected int currentPositionType; 51 | 52 | 53 | public static int ZOOM = 16; 54 | public static final float SKEW = 0.0f; 55 | public static final int ROTATE = 0; 56 | 57 | protected final static int TIME_INTERVAL = 1; 58 | protected final static int TIME_PER_INTERVAL = 5; 59 | 60 | protected int PADDING_MAP; 61 | 62 | protected MapHelper mapHelper; 63 | 64 | 65 | public View onCreateView(LayoutInflater layoutinflater, 66 | ViewGroup viewgroup, Bundle bundle) { 67 | currentMapStatus = REAL_LOCATION; 68 | return super.onCreateView(layoutinflater, viewgroup, bundle); 69 | } 70 | 71 | public void registOnMapClickCallback(OnMapClickCallback clickCallback) { 72 | this.onMapClickCallback = clickCallback; 73 | } 74 | 75 | protected abstract MapHelper createMapHelper(T fiveMap, Context context); 76 | 77 | public abstract void addMyLocationMarker(); 78 | 79 | public void setOnMarkerOnclickListener(OnMarkerOnclickListener listener) { 80 | mOnMarkerOnclickListener = listener; 81 | } 82 | 83 | protected MapCenterChangeListener mMapCenterChangeListener; 84 | 85 | public void setMapCenterChangeListener(MapCenterChangeListener mapCenterChangeListener) { 86 | this.mMapCenterChangeListener = mapCenterChangeListener; 87 | } 88 | 89 | public void setOnPKMapTouchListener(OnPKMapTouch fiveMapTouchListener) { 90 | this.mOnPKMapTouch = fiveMapTouchListener; 91 | } 92 | 93 | public void setSmoothListener(PKSmoothListener fiveSmoothListener) { 94 | mPKSmoothListener = fiveSmoothListener; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/MapFramentFactory.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | import android.os.Bundle; 4 | 5 | import pk.com.lib.map.amp.AmapFragment; 6 | 7 | 8 | /** 9 | * Created by pukai on 2016-4-26. 10 | *

    11 | * 地图工厂类,根据CODE创建地图 12 | */ 13 | public class MapFramentFactory { 14 | public final static int TENCENT_MAP_CODE = 0; 15 | public final static int AMAP_MAP_CODE = 1; 16 | 17 | public static MapFrament createMapFrament(int mapCode, Bundle bundle) { 18 | MapFrament mapFrament = null; 19 | 20 | if (mapCode == AMAP_MAP_CODE) { 21 | mapFrament = AmapFragment.newInstance(bundle); 22 | } 23 | return mapFrament; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/MapHelper.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | import android.content.Context; 4 | 5 | import pk.com.lib.map.control.IControl; 6 | import pk.com.lib.map.navi.INavi; 7 | import pk.com.lib.map.overlay.IOverLay; 8 | import pk.com.lib.map.smooth.ISmooth; 9 | import pk.com.lib.map.trace.ITrace; 10 | 11 | 12 | /** 13 | * Created by pukai on 16/12/21. 14 | */ 15 | public abstract class MapHelper { 16 | private T mFiveMap; 17 | private Context mContext; 18 | public INavi mINavi; 19 | public ITrace mITrace; 20 | public IControl mIControl; 21 | public ISmooth mISoomth; 22 | public IOverLay mIOverLay; 23 | 24 | public MapHelper(T fiveMap, Context context) { 25 | mFiveMap = fiveMap; 26 | mContext = context; 27 | mINavi = createNaive(mFiveMap, mContext); 28 | mITrace = createTrace(mFiveMap, mContext); 29 | mIControl = createControl(mFiveMap, mContext); 30 | mISoomth = createSmooth(mFiveMap, mContext); 31 | mIOverLay = createOverLay(mFiveMap, mContext); 32 | } 33 | 34 | protected abstract INavi createNaive(T fiveMap, Context context); 35 | 36 | protected abstract ITrace createTrace(T fiveMap, Context context); 37 | 38 | protected abstract IControl createControl(T fiveMap, Context context); 39 | 40 | protected abstract ISmooth createSmooth(T fiveMap, Context context); 41 | 42 | protected abstract IOverLay createOverLay(T fiveMap, Context context); 43 | 44 | 45 | public void destrory() { 46 | mFiveMap = null; 47 | mContext = null; 48 | if (mINavi != null) { 49 | mINavi.destroy(); 50 | mINavi = null; 51 | } 52 | if (mITrace != null) { 53 | mITrace.destroy(); 54 | mITrace = null; 55 | } 56 | if (mIControl != null) { 57 | mIControl.destroy(); 58 | mIControl = null; 59 | } 60 | if (mIOverLay != null) { 61 | mIOverLay.destroy(); 62 | mIOverLay = null; 63 | } 64 | if (mISoomth != null) { 65 | mISoomth.destroy(); 66 | mISoomth = null; 67 | } 68 | } 69 | 70 | public MapHelper(INavi mINavi, ITrace mITrace, IControl mIControl, ISmooth mISoomth, IOverLay mIOverLay) { 71 | this.mINavi = mINavi; 72 | this.mITrace = mITrace; 73 | this.mIControl = mIControl; 74 | this.mISoomth = mISoomth; 75 | this.mIOverLay = mIOverLay; 76 | } 77 | 78 | public IOverLay getmIOverLay() { 79 | return mIOverLay; 80 | } 81 | 82 | public void setmIOverLay(IOverLay mIOverLay) { 83 | this.mIOverLay = mIOverLay; 84 | } 85 | 86 | public INavi getmINavi() { 87 | return mINavi; 88 | } 89 | 90 | public void setmINavi(INavi mINavi) { 91 | this.mINavi = mINavi; 92 | } 93 | 94 | public ITrace getmITrace() { 95 | return mITrace; 96 | } 97 | 98 | public void setmITrace(ITrace mITrace) { 99 | this.mITrace = mITrace; 100 | } 101 | 102 | public IControl getmIControl() { 103 | return mIControl; 104 | } 105 | 106 | public void setmIControl(IControl mIControl) { 107 | this.mIControl = mIControl; 108 | } 109 | 110 | public ISmooth getmISoomth() { 111 | return mISoomth; 112 | } 113 | 114 | public void setmISoomth(ISmooth mISoomth) { 115 | this.mISoomth = mISoomth; 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/MapResource.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | import android.content.Context; 4 | import android.graphics.Point; 5 | 6 | /** 7 | * Created by pukai on 16/12/22. 8 | */ 9 | public class MapResource { 10 | /**屏幕的左边界 最小间距 单位px**/ 11 | private final static int LEFT_BORDER = 30; 12 | /**屏幕的右边界 最小间距 单位px**/ 13 | private final static int RIGHT_BORDER = 30; 14 | /**屏幕的上边界 最小间距 单位px**/ 15 | private final static int TOP_BORDER = 30; 16 | /**屏幕的下边界 最小间距 单位px**/ 17 | private final static int BOTTOM_BORDER = 30; 18 | /** 当前地图的缩放等级**/ 19 | public static float ZOOM = 16; 20 | /** 当前地图的方向**/ 21 | public static float BEARING = 0; 22 | /**当前地图的旋转角度**/ 23 | public static float TILT = 0; 24 | /**屏幕的宽高**/ 25 | private Point screenPoint; 26 | 27 | /** 基础地图资源**/ 28 | protected T mPKMap; 29 | 30 | protected Context mContext; 31 | 32 | 33 | public void initMapResource(T fiveMap, Context context) { 34 | mPKMap = fiveMap; 35 | mContext = context; 36 | } 37 | 38 | protected void destroy() { 39 | mPKMap = null; 40 | mContext = null; 41 | } 42 | 43 | /* private boolean isPointInCurrentScreen(LatLng latLng) { 44 | if (screenPoint == null || screenPoint.equals(0, 0)) { 45 | screenPoint = DensityUtil.getScrenWidth(mContext); 46 | } 47 | Point point = mFiveMap.getAMap().getProjection().toScreenLocation(latLng); 48 | return point.x < LEFT_BORDER | point.x > screenPoint.x - RIGHT_BORDER || point.y < TOP_BORDER || point.y > screenPoint.y - BOTTOM_BORDER; 49 | }*/ 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/MapUtil.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.pm.PackageInfo; 6 | import android.content.pm.PackageManager; 7 | import android.net.Uri; 8 | 9 | 10 | import java.net.URISyntaxException; 11 | import java.text.DecimalFormat; 12 | import java.util.List; 13 | 14 | import pk.com.lib.map.modle.PKLatLng; 15 | 16 | /** 17 | * Created by dongfang on 2016/4/28. 18 | */ 19 | public class MapUtil { 20 | 21 | /** 22 | * 百度地图安装标识 23 | */ 24 | public static final int MAY_TYPE_BAIDU = 0x1; 25 | /** 26 | * 高德地图安装标识 27 | */ 28 | public static final int MAY_TYPE_GAODE = 0x10; 29 | /** 30 | * Google地图安装标识 31 | */ 32 | public static final int MAY_TYPE_GOOGLE = 0x100; 33 | /** 34 | * 腾讯地图内部导航 35 | */ 36 | public static final int MAY_TYPE_TENCENT = 0x1000; 37 | 38 | private static final String MAP_PACKAGE_NAME_BAIDU = "com.baidu.BaiduMap"; 39 | private static final String MAP_PACKAGE_NAME_GAODE = "com.autonavi.minimap"; 40 | private static final String MAP_PACKAGE_NAME_GOOGLE = "com.google.android.apps.maps"; 41 | 42 | private static double a = 6378245.0; 43 | private static double ee = 0.00669342162296594323; 44 | private static double pi = 3.14159265358979324; 45 | private static double x_pi = pi * 3000.0 / 180.0; 46 | private static DecimalFormat sDecimalFormat = new DecimalFormat("#.000000"); //保留6位 47 | 48 | /** 49 | * 获取终端上安装的导航软件
    50 | *

    51 | * 1. 百度导航值 {@link MapUtil#MAY_TYPE_BAIDU}
    52 | * 2. 高德导航值 {@link MapUtil#MAY_TYPE_GAODE}
    53 | * 3. 谷歌导航值 {@link MapUtil#MAY_TYPE_GOOGLE}
    54 | * 55 | * @param context 56 | * @return 若没有安装导航软件,返回0 ,反正返回安装导航软件的‘与’值 57 | */ 58 | public static int getMapInstallType(Context context) { 59 | int type = 0; 60 | final PackageManager packageManager = context.getPackageManager(); 61 | // 获取所有已安装程序的包信息 62 | List pinfo = packageManager.getInstalledPackages(0); 63 | String packageName = ""; 64 | for (int i = 0, l = pinfo.size(); i < l; i++) { 65 | packageName = pinfo.get(i).packageName; 66 | if (packageName.equalsIgnoreCase(MAP_PACKAGE_NAME_BAIDU)) { 67 | type |= MAY_TYPE_BAIDU; 68 | } else if (packageName.equalsIgnoreCase(MAP_PACKAGE_NAME_GAODE)) { 69 | type |= MAY_TYPE_GAODE; 70 | } else if (packageName.equalsIgnoreCase(MAP_PACKAGE_NAME_GOOGLE)) { 71 | type |= MAY_TYPE_GOOGLE; 72 | } 73 | } 74 | return type; 75 | } 76 | 77 | /** 78 | * 使用高德地图进行导航 79 | * 80 | * @param context 81 | * @param endLat 结束纬度 82 | * @param endLng 结束经度 83 | * @param endAdrress 地址名称 84 | */ 85 | public static void navi2GaoDe(Context context, double endLat, double endLng, String endAdrress) { 86 | Intent intent = new Intent("android.intent.action.VIEW", 87 | Uri.parse("androidamap://navi?sourceApplication=" + endAdrress 88 | + "&lat=" + endLat 89 | + "&lon=" + endLng 90 | + "&dev=0")); 91 | 92 | intent.setPackage("com.autonavi.minimap"); 93 | try { 94 | context.startActivity(intent); // 启动调用 95 | } catch (Exception e) { 96 | e.printStackTrace(); 97 | } 98 | } 99 | 100 | /** 101 | * 使用百度地图进行导航 102 | * 103 | * @param context 104 | * @param startLat 开始纬度 105 | * @param startLng 开始经度 106 | * @param endLat 结束纬度 107 | * @param endLng 结束经度 108 | * @param endAdrress 地址名称 109 | */ 110 | public static void navi2BaiDu(Context context, 111 | double startLat, double startLng, 112 | double endLat, double endLng, String endAdrress) { 113 | try { 114 | Intent intent = Intent.parseUri("intent://map/direction?" 115 | + "coord_type=gcj02" // 表示使用火星坐标系统 116 | + "&origin=|latlng:" + startLat + "," + startLng 117 | + "&destination=" + endAdrress 118 | + "|latlng:" + endLat + "," + endLng 119 | + "&mode=driving&src=" + context.getPackageName() 120 | + "|" + "RentPK" // 故意这么写的// + context.getString(R.string.app_name) 121 | + "#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end" 122 | , 0); 123 | 124 | context.startActivity(intent); 125 | } catch (URISyntaxException e) { 126 | e.printStackTrace(); 127 | } 128 | } 129 | 130 | /** 131 | * 使用谷歌地图进行导航 132 | * 133 | * @param context 134 | * @param startLat 开始纬度 135 | * @param startLng 开始经度 136 | * @param endLat 结束纬度 137 | * @param endLng 结束经度 138 | */ 139 | public static void navi2Google(Context context, 140 | double startLat, double startLng, 141 | double endLat, double endLng) { 142 | Uri uri = Uri.parse( 143 | "http://maps.google.com/maps?" 144 | + "saddr=" + startLat + "," + startLng 145 | + "&" 146 | + "daddr=" + endLat + "," + endLng 147 | ); 148 | Intent intent = new Intent(Intent.ACTION_VIEW, uri); 149 | // If you want to get rid of the dialog,Before the startActivity() add this 150 | intent.setClassName(MAP_PACKAGE_NAME_GOOGLE, "com.google.android.maps.MapsActivity"); 151 | context.startActivity(intent); 152 | } 153 | 154 | public static PKLatLng transGoogle2Amap(double lat, double lng) { 155 | return transform2Mars(lat, lng); 156 | } 157 | 158 | /** 159 | * 地球坐标转换火星坐标 160 | * 161 | * @param wgLat 地球纬度 162 | * @param wgLon 地球经度 163 | * @return 164 | */ 165 | private static PKLatLng transform2Mars(double wgLat, double wgLon) { 166 | double dLat = transform2MarsLat(wgLon - 105.0, wgLat - 35.0); 167 | double dLon = transform2MarsLng(wgLon - 105.0, wgLat - 35.0); 168 | double radLat = wgLat / 180.0 * pi; 169 | double magic = Math.abs(radLat); 170 | magic = 1 - ee * magic * magic; 171 | double sqrtMagic = Math.sqrt(magic); 172 | dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); 173 | dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); 174 | double mgLat = wgLat + dLat; 175 | double mgLon = wgLon + dLon; 176 | return new PKLatLng(Double.valueOf(sDecimalFormat.format(mgLat)), Double.valueOf(sDecimalFormat.format(mgLon))); 177 | } 178 | 179 | /** 180 | * 火星坐标转换百度坐标 181 | * 182 | * @param gcLat 地球纬度 183 | * @param gcLng 地球经度 184 | * @return 185 | */ 186 | public static PKLatLng transform2BaiDu(double gcLat, double gcLng) { 187 | double x = gcLng, y = gcLat; 188 | double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi); 189 | double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi); 190 | double bdLat = z * Math.sin(theta) + 0.006; 191 | double bdLng = z * Math.cos(theta) + 0.0065; 192 | return new PKLatLng(bdLat, bdLng); 193 | } 194 | 195 | /** 196 | * 地球坐标转换火星坐标 197 | * 198 | * @param wglat 地球纬度 199 | * @param wglng 地球经度 200 | * @return 纬度 201 | */ 202 | private static double transform2MarsLat(double wglat, double wglng) { 203 | double ret = -100.0 + 2.0 * wglat + 3.0 * wglng + 0.2 * wglng * wglng + 0.1 * wglat * wglng + 0.2 * Math.sqrt(Math.abs(wglat)); 204 | ret += (20.0 * Math.sin(6.0 * wglat * pi) + 20.0 * Math.sin(2.0 * wglat * pi)) * 2.0 / 3.0; 205 | ret += (20.0 * Math.sin(wglng * pi) + 40.0 * Math.sin(wglng / 3.0 * pi)) * 2.0 / 3.0; 206 | ret += (160.0 * Math.sin(wglng / 12.0 * pi) + 320 * Math.sin(wglng * pi / 30.0)) * 2.0 / 3.0; 207 | return ret; 208 | } 209 | 210 | /** 211 | * 地球坐标转换火星坐标 212 | * 213 | * @param wglat 地球纬度 214 | * @param wglng 地球经度 215 | * @return 经度 216 | */ 217 | private static double transform2MarsLng(double wglat, double wglng) { 218 | double ret = 300.0 + wglat + 2.0 * wglng + 0.1 * wglat * wglat + 0.1 * wglat * wglng + 0.1 * Math.sqrt(Math.abs(wglat)); 219 | ret += (20.0 * Math.sin(6.0 * wglat * pi) + 20.0 * Math.sin(2.0 * wglat * pi)) * 2.0 / 3.0; 220 | ret += (20.0 * Math.sin(wglat * pi) + 40.0 * Math.sin(wglat / 3.0 * pi)) * 2.0 / 3.0; 221 | ret += (150.0 * Math.sin(wglat / 12.0 * pi) + 300.0 * Math.sin(wglat / 30.0 * pi)) * 2.0 / 3.0; 222 | return ret; 223 | } 224 | 225 | 226 | /** 227 | * 火星坐标转百度坐标 228 | * 229 | * @param gcLat 火星坐标纬度 230 | * @param gcLng 火星坐标经度 231 | * @return 百度坐标经度 232 | */ 233 | private static double transform2BaiDuLng(double gcLat, double gcLng) { 234 | double x = gcLng, y = gcLat; 235 | double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi); 236 | double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi); 237 | return z * Math.cos(theta) + 0.0065; 238 | } 239 | 240 | /** 241 | * 火星坐标转百度坐标 242 | * 243 | * @param gcLat 火星坐标纬度 244 | * @param gcLng 火星坐标经度 245 | * @return 百度坐标纬度 246 | */ 247 | private static double transform2BaiDuLat(double gcLat, double gcLng) { 248 | double x = gcLng, y = gcLat; 249 | double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi); 250 | double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi); 251 | return z * Math.sin(theta) + 0.006; 252 | } 253 | 254 | public static boolean isTheSamePlace(PKLatLng fiveLatLng1, PKLatLng fiveLatLng2) { 255 | //// TODO: 17/2/14 判断两个点是否为同一个点 256 | return (Math.abs(fiveLatLng1.getLatitude() - fiveLatLng2.getLatitude()) < 0.0001 && Math.abs(fiveLatLng1.getLongitude() - fiveLatLng2.getLongitude()) < 0.0001); 257 | } 258 | 259 | public static boolean isTheSameLatlng(PKLatLng fiveLatLng1, PKLatLng fiveLatLng2) { 260 | // 17/2/14 判断两个点经纬度的误差 261 | return (Math.abs(fiveLatLng1.getLatitude() - fiveLatLng2.getLatitude()) < 0.0000001 && Math.abs(fiveLatLng1.getLongitude() - fiveLatLng2.getLongitude()) < 0.0000001); 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/NaviCallBack.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | /** 4 | * Created by pukai on 16/5/19. 5 | */ 6 | public interface NaviCallBack { 7 | void naviOnStart(); 8 | void naviOnStop(); 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/OnMapClickCallback.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | 4 | import pk.com.lib.map.modle.PKMarker; 5 | 6 | /** 7 | * Created by pukai on 2016-4-27. 8 | * 9 | * 地图公共的点击回调接口 10 | */ 11 | public interface OnMapClickCallback { 12 | /** 13 | * 地图点击的回调事件 14 | * @param fiveMarker 返回添加的标注 15 | */ 16 | void onMapClicked(PKMarker fiveMarker); 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/OnMapLoaded.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | import pk.com.lib.CommonMapFunction; 4 | 5 | /** 6 | * Created by pukai on 16/5/9. 7 | */ 8 | public interface OnMapLoaded { 9 | void mapLoadSuccess(CommonMapFunction commonMapFunction); 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/OnMarkerOnclickListener.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | /** 4 | * Created by pukai on 17/2/14. 5 | */ 6 | public interface OnMarkerOnclickListener { 7 | void markerIsClicked(); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/OnPKMapTouch.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map; 2 | 3 | /** 4 | * Created by pukai on 17/2/17. 5 | */ 6 | public interface OnPKMapTouch { 7 | void onMapTouch(); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/amp/AMapHelper.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.amp; 2 | 3 | import android.content.Context; 4 | 5 | import com.amap.api.maps.AMap; 6 | 7 | import pk.com.lib.map.MapHelper; 8 | import pk.com.lib.map.control.AMapControl; 9 | import pk.com.lib.map.control.IControl; 10 | import pk.com.lib.map.navi.AMapNavi; 11 | import pk.com.lib.map.navi.INavi; 12 | import pk.com.lib.map.overlay.AMapOverLay; 13 | import pk.com.lib.map.overlay.IOverLay; 14 | import pk.com.lib.map.smooth.AMapSooth; 15 | import pk.com.lib.map.smooth.ISmooth; 16 | import pk.com.lib.map.trace.AMapTrace; 17 | import pk.com.lib.map.trace.ITrace; 18 | 19 | 20 | /** 21 | * Created by pukai on 16/12/22. 22 | */ 23 | public class AMapHelper extends MapHelper { 24 | public AMapHelper(AMap aMap,Context context){ 25 | super(aMap,context); 26 | } 27 | public INavi createNaive(AMap fiveMap, Context context){ 28 | return new AMapNavi(fiveMap,context); 29 | } 30 | 31 | @Override 32 | protected ITrace createTrace(AMap fiveMap, Context context) { 33 | return new AMapTrace(fiveMap,context); 34 | } 35 | 36 | @Override 37 | protected IControl createControl(AMap fiveMap, Context context) { 38 | return new AMapControl(fiveMap,context); 39 | } 40 | 41 | @Override 42 | protected ISmooth createSmooth(AMap fiveMap, Context context) { 43 | return new AMapSooth(fiveMap,context); 44 | } 45 | 46 | @Override 47 | protected IOverLay createOverLay(AMap fiveMap, Context context) { 48 | return new AMapOverLay(fiveMap,context); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/amp/AmapFragment.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.amp; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.LayoutInflater; 7 | import android.view.MotionEvent; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.ImageView; 11 | import android.widget.TextView; 12 | 13 | import com.amap.api.maps.AMap; 14 | import com.amap.api.maps.MapView; 15 | import com.amap.api.maps.model.CameraPosition; 16 | import com.amap.api.maps.model.Marker; 17 | 18 | import java.util.List; 19 | 20 | import pk.com.lib.R; 21 | import pk.com.lib.map.MapFrament; 22 | import pk.com.lib.map.MapHelper; 23 | import pk.com.lib.map.modle.PKLatLng; 24 | import pk.com.lib.map.modle.PKListLatLngContainer; 25 | import pk.com.lib.map.modle.PKMarker; 26 | 27 | /** 28 | * Created by pukai on 2016-6-20. 29 | */ 30 | public class AmapFragment extends MapFrament implements AMap.OnMapLoadedListener, AMap.OnMarkerClickListener, AMap.OnCameraChangeListener, AMap.OnMapTouchListener { 31 | private AMap mAMap; 32 | private MapView mMapView; 33 | //记录当前添加的marker 再次添加的时候 只需要更改marker的位置 setPotint(); 34 | private PKMarker currentMaker; 35 | 36 | @Override 37 | public View onCreateView(LayoutInflater layoutinflater, ViewGroup viewgroup, Bundle bundle) { 38 | View view = layoutinflater.inflate(R.layout.fragment_gaode_map, viewgroup, false); 39 | mMapView = (MapView) view.findViewById(R.id.amapView); 40 | mMapView.onCreate(bundle); 41 | mAMap = mMapView.getMap(); 42 | 43 | mAMap.getUiSettings().setLogoPosition(50); 44 | mAMap.getUiSettings().setZoomControlsEnabled(false); 45 | 46 | mapHelper = createMapHelper(mAMap, getContext()); 47 | mAMap.setOnMarkerClickListener(this); 48 | mAMap.setOnMapLoadedListener(this); 49 | mAMap.setOnCameraChangeListener(this); 50 | mAMap.setOnMapTouchListener(this); 51 | return view; 52 | } 53 | 54 | @Override 55 | protected MapHelper createMapHelper(AMap fiveMap, Context context) { 56 | return new AMapHelper(fiveMap, context); 57 | } 58 | 59 | 60 | @Override 61 | public void onDestroy() { 62 | mMapView.onDestroy(); 63 | mMapView = null; 64 | mapHelper.destrory(); 65 | super.onDestroy(); 66 | } 67 | 68 | @Override 69 | public void onResume() { 70 | super.onResume(); 71 | mMapView.onResume(); 72 | } 73 | 74 | @Override 75 | public void onPause() { 76 | super.onPause(); 77 | mMapView.onPause(); 78 | } 79 | 80 | @Override 81 | public void onSaveInstanceState(Bundle outState) { 82 | super.onSaveInstanceState(outState); 83 | mMapView.onSaveInstanceState(outState); 84 | } 85 | 86 | @Override 87 | public void onLowMemory() { 88 | super.onLowMemory(); 89 | mMapView.onLowMemory(); 90 | } 91 | 92 | @Override 93 | public void addMyLocationMarker() { 94 | 95 | } 96 | 97 | @Override 98 | public void onMapLoaded() { 99 | mapHelper.getmIControl().setCenter(new PKLatLng(31.2393627086, 121.4995369338)); 100 | } 101 | 102 | @Override 103 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 104 | } 105 | 106 | /** 107 | * marker点击事件的回调 返回true 事件结束 返回false 继续交给底层处理事件 108 | * 109 | * @param marker 110 | * @return 111 | */ 112 | @Override 113 | public boolean onMarkerClick(Marker marker) { 114 | return false; 115 | } 116 | 117 | public static MapFrament newInstance(Bundle bundle) { 118 | AmapFragment amapFragment = new AmapFragment(); 119 | amapFragment.setArguments(bundle); 120 | return amapFragment; 121 | } 122 | 123 | @Override 124 | public void onCameraChange(CameraPosition cameraPosition) { 125 | 126 | } 127 | 128 | @Override 129 | public void onCameraChangeFinish(CameraPosition cameraPosition) { 130 | 131 | } 132 | 133 | @Override 134 | public void onTouch(MotionEvent motionEvent) { 135 | 136 | } 137 | 138 | @Override 139 | public void setMapCenter(PKLatLng fiveLatLng) { 140 | mapHelper.getmIControl().setCenter(fiveLatLng); 141 | } 142 | 143 | @Override 144 | public void addBusinessMarker(PKLatLng fiveLatLng, String title) { 145 | if (currentMaker == null) { 146 | currentMaker = mapHelper.getmIOverLay().addMarker(fiveLatLng, inflatCarStausView(title), 0.1f, 0.5f); 147 | } else { 148 | currentMaker.getAmaptMarker().setPosition(fiveLatLng.getAmapLatlng()); 149 | } 150 | } 151 | 152 | @Override 153 | public void addPollyLine(List fiveLatLngList) { 154 | mapHelper.getmIOverLay().addPollyLine(new PKListLatLngContainer(fiveLatLngList)); 155 | } 156 | 157 | @Override 158 | public void moveMap(List fiveLatLngList) { 159 | mapHelper.getmIControl().setLatLng(fiveLatLngList); 160 | } 161 | 162 | 163 | public View inflatCarStausView(String title) { 164 | View view = LayoutInflater.from(getContext()).inflate(R.layout.item_marker_car, null); 165 | TextView data = (TextView) view.findViewById(R.id.item_marker_car_data); 166 | ImageView imageView = (ImageView) view.findViewById(R.id.item_marker_car_image); 167 | imageView.setImageResource(R.drawable.btn_car_moving_press); 168 | data.setTextColor(getContext().getResources().getColor(R.color.ct0)); 169 | data.setText(title); 170 | return view; 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/control/AMapControl.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.control; 2 | 3 | import android.content.Context; 4 | 5 | import com.amap.api.maps.AMap; 6 | import com.amap.api.maps.CameraUpdate; 7 | import com.amap.api.maps.CameraUpdateFactory; 8 | import com.amap.api.maps.model.CameraPosition; 9 | import com.amap.api.maps.model.LatLngBounds; 10 | 11 | import java.util.List; 12 | 13 | import pk.com.lib.map.modle.PKLatLng; 14 | 15 | 16 | /** 17 | * Created by pukai on 16/12/22. 18 | */ 19 | public class AMapControl extends IControl { 20 | public AMapControl(AMap aMap, Context context) { 21 | initMapResource(aMap, context); 22 | } 23 | 24 | @Override 25 | public void setLatLng(List fiveLatLngs) { 26 | if (fiveLatLngs == null || fiveLatLngs.isEmpty()) { 27 | return; 28 | } 29 | LatLngBounds.Builder builder = new LatLngBounds.Builder(); 30 | for (PKLatLng fiveLatLng : fiveLatLngs) { 31 | builder.include(fiveLatLng.getAmapLatlng()); 32 | } 33 | int leftPadding = 100; 34 | int rightPadding = 100; 35 | int topPadding = 100; 36 | int bottomPadding = 251; 37 | 38 | CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBoundsRect(builder.build(), leftPadding, rightPadding, topPadding, bottomPadding); 39 | mPKMap.moveCamera(cameraUpdate); 40 | } 41 | 42 | @Override 43 | public void setCenter(PKLatLng fiveLatLng) { 44 | CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(new CameraPosition(fiveLatLng.getAmapLatlng(), ZOOM, 0, 0)); 45 | mPKMap.moveCamera(cameraUpdate); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/control/IControl.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.control; 2 | 3 | import java.util.List; 4 | 5 | import pk.com.lib.map.MapResource; 6 | import pk.com.lib.map.modle.PKLatLng; 7 | 8 | /** 9 | *

    地图的基础控制

    10 | *
      缩放
    11 | *
      平移
    12 | *
      变换中心点
    13 | * Created by pukai on 16/12/21. 14 | */ 15 | public abstract class IControl extends MapResource { 16 | public abstract void setLatLng(List fiveLatLngs); 17 | 18 | public abstract void setCenter(PKLatLng fiveLatLng); 19 | } -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKContainer.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | /** 4 | * Created by pukai on 16/12/29. 5 | */ 6 | public class PKContainer { 7 | private T data; 8 | 9 | public T getData() { 10 | return data; 11 | } 12 | 13 | public void setData(T data) { 14 | this.data = data; 15 | } 16 | 17 | public PKContainer(T data){ 18 | this.data = data; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKEquipmentMarkerHolder.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | import com.amap.api.maps.model.Marker; 4 | 5 | import java.util.List; 6 | 7 | public class PKEquipmentMarkerHolder { 8 | 9 | public PKEquipmentMarkerHolder(PKLatLng fiveLatLng, List infos) { 10 | this.fiveLatLng = fiveLatLng; 11 | this.infos = infos; 12 | } 13 | public Marker marker; 14 | public PKLatLng fiveLatLng; 15 | public List infos; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKEuipmentInfo.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | public class PKEuipmentInfo { 4 | public PKEuipmentInfo(int status, String title) { 5 | this.status = status; 6 | this.title = title; 7 | } 8 | 9 | public int status; 10 | public String title; 11 | } -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKLatLng.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.amap.api.maps.model.LatLng; 7 | 8 | import java.io.Serializable; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by pukai on 2016-4-26. 14 | * 用于接口传递数据的公共经纬度坐标类 15 | */ 16 | public class PKLatLng implements Serializable, Parcelable { 17 | private static final long serialVersionUID = 1221039181121980934L; 18 | private double latitude; 19 | private double longitude; 20 | private String title; 21 | private String snippet; 22 | 23 | private double bearing; // 方向, 单位为度, 仅当位置来自GPS时可能有效. 24 | private int locationType; // 定位数据来源 25 | private long time; //时间戳 ,long 26 | 27 | 28 | public static long getSerialVersionUID() { 29 | return serialVersionUID; 30 | } 31 | 32 | public double getLatitude() { 33 | return latitude; 34 | } 35 | 36 | public void setLatitude(double latitude) { 37 | this.latitude = latitude; 38 | } 39 | 40 | public double getLongitude() { 41 | return longitude; 42 | } 43 | 44 | public void setLongitude(double longitude) { 45 | this.longitude = longitude; 46 | } 47 | 48 | public String getTitle() { 49 | return title; 50 | } 51 | 52 | public void setTitle(String title) { 53 | this.title = title; 54 | } 55 | 56 | public String getSnippet() { 57 | return snippet; 58 | } 59 | 60 | public void setSnippet(String snippet) { 61 | this.snippet = snippet; 62 | } 63 | 64 | public double getBearing() { 65 | return bearing; 66 | } 67 | 68 | public void setBearing(double bearing) { 69 | this.bearing = bearing; 70 | } 71 | 72 | public int getLocationType() { 73 | return locationType; 74 | } 75 | 76 | public void setLocationType(int locationType) { 77 | this.locationType = locationType; 78 | } 79 | 80 | 81 | public PKLatLng(double latitude, double longitude) { 82 | this.latitude = latitude; 83 | this.longitude = longitude; 84 | } 85 | 86 | public PKLatLng(double latitude, double longitude, String ttile, String snippet) { 87 | this.latitude = latitude; 88 | this.longitude = longitude; 89 | this.title = ttile; 90 | this.snippet = snippet; 91 | } 92 | 93 | public boolean hasZeroValue() { 94 | return latitude == 0.0 || longitude == 0.0; 95 | } 96 | 97 | public PKLatLng(double latitude, double longitude, double bearing, int locType, long time) { 98 | this.latitude = latitude; 99 | this.longitude = longitude; 100 | this.bearing = bearing; 101 | this.locationType = locType; 102 | this.time = time; 103 | } 104 | 105 | public LatLng getAmapLatlng() { 106 | return new LatLng(latitude, longitude); 107 | } 108 | 109 | /** 110 | * socket坐标上报有用,别修改返回格式 111 | * 112 | * @return 113 | */ 114 | @Override 115 | public String toString() { 116 | return latitude + "," + longitude + "," + bearing + "," + locationType + "," + time; 117 | } 118 | 119 | @Override 120 | public int describeContents() { 121 | return 0; 122 | } 123 | 124 | @Override 125 | public void writeToParcel(Parcel dest, int flags) { 126 | dest.writeDouble(this.latitude); 127 | dest.writeDouble(this.longitude); 128 | dest.writeDouble(this.bearing); 129 | dest.writeLong(this.time); 130 | } 131 | 132 | protected PKLatLng(Parcel in) { 133 | this.latitude = in.readDouble(); 134 | this.longitude = in.readDouble(); 135 | this.bearing = in.readDouble(); 136 | this.time = in.readLong(); 137 | } 138 | 139 | public static final Creator CREATOR = new Creator() { 140 | @Override 141 | public PKLatLng createFromParcel(Parcel source) { 142 | return new PKLatLng(source); 143 | } 144 | 145 | @Override 146 | public PKLatLng[] newArray(int size) { 147 | return new PKLatLng[size]; 148 | } 149 | }; 150 | 151 | public static List listPKLatlng2AmapLatlng(List list) { 152 | List amapList = new ArrayList<>(); 153 | if (list != null && !list.isEmpty()) { 154 | for (PKLatLng fiveLatLng : list) { 155 | amapList.add(fiveLatLng.getAmapLatlng()); 156 | } 157 | } 158 | return amapList; 159 | } 160 | 161 | public static List listAmapLatlng2PKLatlng(List list) { 162 | List fiveLatLngs = new ArrayList<>(); 163 | if (list != null && !list.isEmpty()) { 164 | for (LatLng amapLatlng : list) { 165 | fiveLatLngs.add(new PKLatLng(amapLatlng.latitude,amapLatlng.longitude)); 166 | } 167 | } 168 | return fiveLatLngs; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKListLatLngContainer.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | import com.amap.api.maps.model.LatLng; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | *

    f防止各种地图类的List 在接口回调时,多次转换成List 节约时间和空间效率

    9 | * Created by pukai on 16/12/26. 10 | */ 11 | public class PKListLatLngContainer { 12 | private List aMaplist; 13 | 14 | private List fiveLatLngs; 15 | 16 | public List getaMaplist() { 17 | if (aMaplist == null || aMaplist.isEmpty()) { 18 | aMaplist = PKLatLng.listPKLatlng2AmapLatlng(fiveLatLngs); 19 | } 20 | return aMaplist; 21 | } 22 | 23 | public void setaMaplist(List aMaplist) { 24 | this.aMaplist = aMaplist; 25 | } 26 | 27 | public List getPKLatLngs() { 28 | if (fiveLatLngs == null || fiveLatLngs.isEmpty()) { 29 | fiveLatLngs = PKLatLng.listAmapLatlng2PKLatlng(aMaplist); 30 | } 31 | return fiveLatLngs; 32 | } 33 | 34 | public void setPKLatLngs(List fiveLatLngs) { 35 | this.fiveLatLngs = fiveLatLngs; 36 | } 37 | 38 | public PKListLatLngContainer(List aMaplist, List fiveLatLngs) { 39 | this.aMaplist = aMaplist; 40 | this.fiveLatLngs = fiveLatLngs; 41 | } 42 | 43 | public PKListLatLngContainer(List fiveLatLngs) { 44 | this.fiveLatLngs = fiveLatLngs; 45 | } 46 | 47 | public PKListLatLngContainer() { 48 | 49 | } 50 | 51 | public boolean isEmpty() { 52 | return !((fiveLatLngs != null && !fiveLatLngs.isEmpty()) || (aMaplist != null && !aMaplist.isEmpty())); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKListTraceLocationContainer.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | import com.amap.api.trace.TraceLocation; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | *

    防止各种地图类的List 在接口回调时,多次转换成List 节约时间和空间效率

    9 | * Created by pukai on 16/12/26. 10 | */ 11 | public class PKListTraceLocationContainer { 12 | private List aMaplist; 13 | 14 | private List fiveTraceLocations; 15 | 16 | public List getaMaplist() { 17 | if(aMaplist==null||aMaplist.isEmpty()){ 18 | aMaplist = PKTraceLocation.listPKTraceLocation2AmapTraceLocation(fiveTraceLocations); 19 | } 20 | return aMaplist; 21 | } 22 | 23 | public void setaMaplist(List aMaplist) { 24 | this.aMaplist = aMaplist; 25 | } 26 | 27 | public List getPKTraceLocations() { 28 | if(fiveTraceLocations==null||fiveTraceLocations.isEmpty()){ 29 | fiveTraceLocations = PKTraceLocation.listAmapTraceLocation2PKTraceLocation(aMaplist); 30 | } 31 | return fiveTraceLocations; 32 | } 33 | 34 | public void setPKTraceLocations(List fiveTraceLocations) { 35 | this.fiveTraceLocations = fiveTraceLocations; 36 | } 37 | 38 | public PKListTraceLocationContainer(List aMaplist, List fiveTraceLocations) { 39 | this.aMaplist = aMaplist; 40 | this.fiveTraceLocations = fiveTraceLocations; 41 | } 42 | 43 | public PKListTraceLocationContainer(List fiveTraceLocations) { 44 | this.fiveTraceLocations = fiveTraceLocations; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKMarker.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | import com.amap.api.maps.model.Marker; 4 | 5 | /** 6 | * Created by pukai on 2016-4-27. 7 | *

    8 | * 用于传递地图标注的公共标注类 9 | */ 10 | public class PKMarker { 11 | private Marker amapMarker; 12 | 13 | public PKMarker(Marker amapMarker) { 14 | this.amapMarker = amapMarker; 15 | } 16 | 17 | 18 | public void remove() { 19 | if(amapMarker!=null){ 20 | amapMarker.remove(); 21 | } 22 | } 23 | public Marker getAmaptMarker(){ 24 | return amapMarker; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKMarkerHolder.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | /** 4 | * Created by pukai on 17/2/14. 5 | */ 6 | public class PKMarkerHolder { 7 | public PKMarkerHolder(PKLatLng latLng, String t, int s) { 8 | fiveLatLng = latLng; 9 | title = t; 10 | status = s; 11 | } 12 | 13 | public PKLatLng fiveLatLng; 14 | public String title; 15 | public int status; 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKMarkerOptions.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | import com.amap.api.maps.model.MarkerOptions; 4 | 5 | /** 6 | * Created by pukai on 16/5/20. 7 | */ 8 | public class PKMarkerOptions { 9 | private MarkerOptions amapMarkerOptions; 10 | 11 | public MarkerOptions getAmapMarkerOptions() { 12 | return amapMarkerOptions; 13 | } 14 | 15 | public void setAmapMarkerOptions(MarkerOptions amapMarkerOptions) { 16 | this.amapMarkerOptions = amapMarkerOptions; 17 | } 18 | public PKMarkerOptions(MarkerOptions amapMarkerOptions) { 19 | this.amapMarkerOptions = amapMarkerOptions; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKTrace.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | /** 7 | * Created by pukai on 16/12/21. 8 | */ 9 | public class PKTrace implements Parcelable { 10 | private long time; 11 | private double latitude; 12 | private double longitude; 13 | private float bearing; 14 | 15 | public long getTime() { 16 | return time; 17 | } 18 | 19 | public void setTime(long time) { 20 | this.time = time; 21 | } 22 | 23 | public double getLatitude() { 24 | return latitude; 25 | } 26 | 27 | public void setLatitude(double latitude) { 28 | this.latitude = latitude; 29 | } 30 | 31 | public double getLongitude() { 32 | return longitude; 33 | } 34 | 35 | public void setLongitude(double longitude) { 36 | this.longitude = longitude; 37 | } 38 | 39 | public float getBearing() { 40 | return bearing; 41 | } 42 | 43 | public void setBearing(float bearing) { 44 | this.bearing = bearing; 45 | } 46 | 47 | 48 | @Override 49 | public int describeContents() { 50 | return 0; 51 | } 52 | 53 | @Override 54 | public void writeToParcel(Parcel dest, int flags) { 55 | dest.writeLong(this.time); 56 | dest.writeDouble(this.latitude); 57 | dest.writeDouble(this.longitude); 58 | dest.writeFloat(this.bearing); 59 | } 60 | 61 | public PKTrace() { 62 | } 63 | 64 | protected PKTrace(Parcel in) { 65 | this.time = in.readLong(); 66 | this.latitude = in.readDouble(); 67 | this.longitude = in.readDouble(); 68 | this.bearing = in.readFloat(); 69 | } 70 | 71 | public static final Creator CREATOR = new Creator() { 72 | @Override 73 | public PKTrace createFromParcel(Parcel source) { 74 | return new PKTrace(source); 75 | } 76 | 77 | @Override 78 | public PKTrace[] newArray(int size) { 79 | return new PKTrace[size]; 80 | } 81 | }; 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/modle/PKTraceLocation.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.modle; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.amap.api.trace.TraceLocation; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by pukai on 16/12/26. 13 | */ 14 | public class PKTraceLocation implements Parcelable { 15 | 16 | private String deviceId; 17 | 18 | private long receiveTime; 19 | 20 | private float speed; 21 | 22 | private double longitude; 23 | 24 | private double latitude; 25 | 26 | private int direction; 27 | 28 | private int carStatus; 29 | 30 | private int acc; 31 | 32 | private TraceLocation aMapTraceLocation; 33 | 34 | public TraceLocation getAmapTraceLocation() { 35 | if (aMapTraceLocation == null) { 36 | aMapTraceLocation = new TraceLocation(); 37 | aMapTraceLocation.setSpeed(speed); 38 | aMapTraceLocation.setLatitude(latitude); 39 | aMapTraceLocation.setLongitude(latitude); 40 | aMapTraceLocation.setTime(receiveTime); 41 | aMapTraceLocation.setBearing(direction); 42 | } 43 | return aMapTraceLocation; 44 | } 45 | 46 | @Override 47 | public int describeContents() { 48 | return 0; 49 | } 50 | 51 | @Override 52 | public void writeToParcel(Parcel dest, int flags) { 53 | dest.writeString(this.deviceId); 54 | dest.writeLong(this.receiveTime); 55 | dest.writeFloat(this.speed); 56 | dest.writeDouble(this.longitude); 57 | dest.writeDouble(this.latitude); 58 | dest.writeInt(this.direction); 59 | dest.writeInt(this.carStatus); 60 | dest.writeInt(this.acc); 61 | } 62 | 63 | public PKTraceLocation() { 64 | } 65 | 66 | public PKTraceLocation(TraceLocation traceLocation) { 67 | if (traceLocation != null) { 68 | receiveTime = traceLocation.getTime(); 69 | speed = traceLocation.getSpeed(); 70 | longitude = traceLocation.getLongitude(); 71 | latitude = traceLocation.getLatitude(); 72 | direction = (int) traceLocation.getBearing(); 73 | } 74 | } 75 | 76 | protected PKTraceLocation(Parcel in) { 77 | this.deviceId = in.readString(); 78 | this.receiveTime = in.readLong(); 79 | this.speed = in.readFloat(); 80 | this.longitude = in.readDouble(); 81 | this.latitude = in.readDouble(); 82 | this.direction = in.readInt(); 83 | this.carStatus = in.readInt(); 84 | this.acc = in.readInt(); 85 | } 86 | 87 | public static final Creator CREATOR = new Creator() { 88 | @Override 89 | public PKTraceLocation createFromParcel(Parcel source) { 90 | return new PKTraceLocation(source); 91 | } 92 | 93 | @Override 94 | public PKTraceLocation[] newArray(int size) { 95 | return new PKTraceLocation[size]; 96 | } 97 | }; 98 | 99 | public static List listPKTraceLocation2AmapTraceLocation(List fiveTraceLocationList) { 100 | List amapTraceLation = new ArrayList<>(); 101 | if (fiveTraceLocationList == null || fiveTraceLocationList.isEmpty()) { 102 | } else { 103 | for (PKTraceLocation PKTraceLocation : fiveTraceLocationList) { 104 | amapTraceLation.add(PKTraceLocation.getAmapTraceLocation()); 105 | } 106 | } 107 | return amapTraceLation; 108 | } 109 | 110 | public static List listAmapTraceLocation2PKTraceLocation(List aMapTracelocation) { 111 | List fiveTraceLation = new ArrayList<>(); 112 | if (aMapTracelocation == null || aMapTracelocation.isEmpty()) { 113 | } else { 114 | for (TraceLocation amapTraceLocation : aMapTracelocation) { 115 | fiveTraceLation.add(new PKTraceLocation(amapTraceLocation)); 116 | } 117 | } 118 | return fiveTraceLation; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/navi/AMapNavi.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.navi; 2 | 3 | import android.content.Context; 4 | 5 | import com.amap.api.maps.AMap; 6 | 7 | import java.util.List; 8 | 9 | import pk.com.lib.map.modle.PKLatLng; 10 | 11 | 12 | /** 13 | * Created by pukai on 16/12/22. 14 | */ 15 | public class AMapNavi extends INavi{ 16 | public AMapNavi(AMap aMap, Context context){ 17 | initMapResource(aMap,context); 18 | } 19 | @Override 20 | public void startNavi(PKLatLng fiveStart, PKLatLng fiveEnd, List fivePassList) { 21 | } 22 | 23 | @Override 24 | public void stopNavi() { 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/navi/INavi.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.navi; 2 | 3 | import java.util.List; 4 | 5 | import pk.com.lib.map.MapResource; 6 | import pk.com.lib.map.modle.PKLatLng; 7 | 8 | /** 9 | * Created by pukai on 16/12/21. 10 | */ 11 | public abstract class INavi extends MapResource { 12 | abstract void startNavi(PKLatLng fiveStart, PKLatLng fiveEnd, List fivePassList); 13 | 14 | abstract void stopNavi(); 15 | } -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/overlay/AMapOverLay.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.overlay; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.view.View; 6 | 7 | import com.amap.api.maps.AMap; 8 | import com.amap.api.maps.model.BitmapDescriptorFactory; 9 | import com.amap.api.maps.model.LatLng; 10 | import com.amap.api.maps.model.MarkerOptions; 11 | import com.amap.api.maps.model.PolylineOptions; 12 | 13 | 14 | import java.util.List; 15 | 16 | import pk.com.lib.map.modle.PKLatLng; 17 | import pk.com.lib.map.modle.PKListLatLngContainer; 18 | import pk.com.lib.map.modle.PKMarker; 19 | import pk.com.lib.map.modle.PKMarkerOptions; 20 | 21 | /** 22 | * Created by pukai on 16/12/22. 23 | */ 24 | public class AMapOverLay extends IOverLay { 25 | 26 | public AMapOverLay(AMap aMap, Context context) { 27 | initMapResource(aMap, context); 28 | } 29 | 30 | @Override 31 | public PKMarker addMarker(PKMarkerOptions fiveMarkerOptions) { 32 | return null; 33 | } 34 | 35 | @Override 36 | public PKMarker addMarker(PKLatLng fiveLatLng, View view) { 37 | PKMarker fiveMarker = new PKMarker(mPKMap.addMarker(new MarkerOptions().position(fiveLatLng.getAmapLatlng()).title(""))); 38 | fiveMarker.getAmaptMarker().setIcon(BitmapDescriptorFactory.fromView(view)); 39 | return fiveMarker; 40 | } 41 | 42 | @Override 43 | public PKMarker addMarker(PKLatLng fiveLatLng, View view, float anchorX, float anchorY) { 44 | PKMarker fiveMarker = new PKMarker(mPKMap.addMarker(new MarkerOptions().position(fiveLatLng.getAmapLatlng()).title("").anchor(anchorX, anchorY))); 45 | fiveMarker.getAmaptMarker().setIcon(BitmapDescriptorFactory.fromView(view)); 46 | return fiveMarker; 47 | } 48 | 49 | @Override 50 | public PKMarker addMarker(PKLatLng fiveLatLng, int imgId) { 51 | PKMarker fiveMarker = new PKMarker(mPKMap.addMarker(new MarkerOptions() 52 | .position(fiveLatLng.getAmapLatlng()) 53 | .rotateAngle((float) fiveLatLng.getBearing()) 54 | )); 55 | fiveMarker.getAmaptMarker().setIcon(BitmapDescriptorFactory.fromResource(imgId)); 56 | return fiveMarker; 57 | } 58 | 59 | @Override 60 | public PKMarker addMarker(PKLatLng fiveLatLng, String title) { 61 | return null; 62 | } 63 | 64 | @Override 65 | public PKMarker addMarker(PKLatLng fiveLatLng, String title, boolean isInfoWindowShow) { 66 | return null; 67 | } 68 | 69 | @Override 70 | public PKMarker addMarker(PKLatLng fiveLatLng, String title, int imgID, boolean isInfoWindowShow) { 71 | return null; 72 | } 73 | 74 | @Override 75 | public PKMarker addMarker(PKLatLng fiveLatLng, String title, int imgID) { 76 | return null; 77 | } 78 | 79 | @Override 80 | public void addPollyLine(PKListLatLngContainer fiveListLatLngContainer) { 81 | if (fiveListLatLngContainer == null || fiveListLatLngContainer.isEmpty()) { 82 | return; 83 | } 84 | List list = fiveListLatLngContainer.getaMaplist(); 85 | addPollyLine(list); 86 | } 87 | 88 | @Override 89 | public void addPollyLine(List list) { 90 | if (list == null || list.size() <= 1) { 91 | return; 92 | } 93 | mPKMap.addPolyline(new PolylineOptions().color(Color.BLUE) 94 | .addAll(list) 95 | .useGradient(true) 96 | .width(16)); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/overlay/IOverLay.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.overlay; 2 | 3 | import android.view.View; 4 | 5 | import com.amap.api.maps.model.LatLng; 6 | 7 | 8 | import java.util.List; 9 | 10 | import pk.com.lib.map.MapResource; 11 | import pk.com.lib.map.modle.PKLatLng; 12 | import pk.com.lib.map.modle.PKListLatLngContainer; 13 | import pk.com.lib.map.modle.PKMarker; 14 | import pk.com.lib.map.modle.PKMarkerOptions; 15 | 16 | /** 17 | * Created by pukai on 16/12/21. 18 | */ 19 | public abstract class IOverLay extends MapResource { 20 | /** 21 | * 添加标注 22 | * 23 | * @param fiveMarkerOptions 24 | */ 25 | public abstract PKMarker addMarker(PKMarkerOptions fiveMarkerOptions); 26 | 27 | /** 28 | * 添加标注 29 | * 30 | * @param fiveLatLng 31 | * @param view 32 | */ 33 | public abstract PKMarker addMarker(PKLatLng fiveLatLng, View view); 34 | 35 | /** 36 | * 添加标注 37 | * 38 | * @param fiveLatLng 39 | * @param view 40 | * @param anchorX 锚点的x 41 | * @param anchorY 锚点的y 42 | */ 43 | public abstract PKMarker addMarker(PKLatLng fiveLatLng, View view, float anchorX, float anchorY); 44 | 45 | /** 46 | * 添加标注 47 | * 48 | * @param fiveLatLng 经纬度坐标信息 49 | * @return 经过封装的PKarker类 50 | */ 51 | public abstract PKMarker addMarker(PKLatLng fiveLatLng, int imgId); 52 | 53 | /** 54 | * 添加标注 55 | * 56 | * @param fiveLatLng 经纬度坐标信息 57 | * @param title 标题 58 | * @return 经过封装的PKarker类 59 | */ 60 | public abstract PKMarker addMarker(PKLatLng fiveLatLng, String title); 61 | 62 | /** 63 | * 添加标注 64 | * 65 | * @param fiveLatLng 经纬度坐标信息 66 | * @param title 标题 67 | * @param isInfoWindowShow 标注框是否显示 68 | * @return 经过封装的PKarker类 69 | */ 70 | public abstract PKMarker addMarker(PKLatLng fiveLatLng, String title, boolean isInfoWindowShow); 71 | 72 | /** 73 | * 添加标注 74 | * 75 | * @param fiveLatLng 经纬度坐标信息 76 | * @param title 标题 77 | * @param isInfoWindowShow 标注框是否显示 78 | * @return 经过封装的PKarker类 79 | */ 80 | public abstract PKMarker addMarker(PKLatLng fiveLatLng, String title, int imgID, boolean isInfoWindowShow); 81 | 82 | /** 83 | * 添加标注使用特定的图标 84 | * 85 | * @param fiveLatLng 经纬度坐标信息 86 | * @param title 标题 87 | * @return 经过封装的PKarker类 88 | */ 89 | public abstract PKMarker addMarker(PKLatLng fiveLatLng, String title, int imgID); 90 | 91 | public abstract void addPollyLine(PKListLatLngContainer fiveListLatLngContainer); 92 | 93 | public abstract void addPollyLine(List latLngs); 94 | 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/smooth/AMapSooth.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.smooth; 2 | 3 | import android.content.Context; 4 | import android.util.Pair; 5 | 6 | import com.amap.api.maps.AMap; 7 | import com.amap.api.maps.model.BitmapDescriptorFactory; 8 | import com.amap.api.maps.model.LatLng; 9 | import com.amap.api.maps.model.MarkerOptions; 10 | import com.amap.api.maps.model.PolylineOptions; 11 | import com.amap.api.maps.utils.SpatialRelationUtil; 12 | import com.amap.api.maps.utils.overlay.SmoothMoveMarker; 13 | 14 | 15 | import java.util.List; 16 | 17 | import pk.com.lib.R; 18 | import pk.com.lib.map.modle.PKLatLng; 19 | import pk.com.lib.map.modle.PKListLatLngContainer; 20 | 21 | /** 22 | * Created by pukai on 16/12/22. 23 | */ 24 | public class AMapSooth extends ISmooth { 25 | 26 | private SmoothMoveMarker smoothMoveMarker; 27 | private PKSmoothListener mPKSmoothListener; 28 | private int color; 29 | private int currentIndex; 30 | private int mTotalDuration; 31 | private PKListLatLngContainer mPKListLatLngContainer; 32 | 33 | public AMapSooth(AMap aMap, Context context) { 34 | initMapResource(aMap, context); 35 | } 36 | 37 | @Override 38 | public void initSmooth(int color, int totalDuration, PKListLatLngContainer fiveListLatLngContainer, PKSmoothListener fiveSmoothListener) { 39 | if (fiveListLatLngContainer == null || fiveListLatLngContainer.isEmpty()) { 40 | return; 41 | } 42 | 43 | mTotalDuration = totalDuration; 44 | mPKListLatLngContainer = fiveListLatLngContainer; 45 | mPKSmoothListener = fiveSmoothListener; 46 | currentIndex = 0; 47 | this.color = color; 48 | final List points = fiveListLatLngContainer.getaMaplist(); 49 | addLine(points); 50 | smoothMoveMarker = new SmoothMoveMarker(mPKMap); 51 | smoothMoveMarker.setDescriptor(BitmapDescriptorFactory.fromResource(R.drawable.icon_car)); 52 | LatLng drivePoint = points.get(0); 53 | final Pair pair = SpatialRelationUtil.calShortestDistancePoint(points, drivePoint); 54 | points.set(pair.first, drivePoint); 55 | List subList = points.subList(pair.first, points.size()); 56 | smoothMoveMarker.setPoints(subList); 57 | smoothMoveMarker.setTotalDuration(totalDuration); 58 | smoothMoveMarker.getMarker().hideInfoWindow(); 59 | smoothMoveMarker.setMoveListener(new SmoothMoveMarker.MoveListener() { 60 | @Override 61 | public void move(final double distance) { 62 | if (mPKSmoothListener != null) { 63 | LatLng latLng = points.get(currentIndex++); 64 | mPKSmoothListener.move(distance, new PKLatLng(latLng.latitude, latLng.longitude), currentIndex); 65 | if (distance == 0) { 66 | mPKSmoothListener.smoothFinish(); 67 | } 68 | } 69 | } 70 | 71 | }); 72 | mPKMap.addMarker(new MarkerOptions().position(points.get(points.size() - 1)).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_end))); 73 | // smoothMoveMarker.startSmoothMove(); 74 | } 75 | 76 | private void addLine(List list) { 77 | mPKMap.addPolyline(new PolylineOptions().color(color) 78 | .addAll(list) 79 | .useGradient(true) 80 | .width(16)); 81 | } 82 | 83 | @Override 84 | public void stopSmooth() { 85 | if (smoothMoveMarker != null) { 86 | smoothMoveMarker.stopMove(); 87 | } 88 | } 89 | 90 | @Override 91 | public void reStartSmooth() { 92 | if (smoothMoveMarker != null) { 93 | smoothMoveMarker.destroy(); 94 | mPKMap.clear(); 95 | smoothMoveMarker = null; 96 | } 97 | initSmooth(color, mTotalDuration, mPKListLatLngContainer, mPKSmoothListener); 98 | startSmooth(); 99 | } 100 | 101 | @Override 102 | public void startSmooth() { 103 | if (smoothMoveMarker != null) { 104 | smoothMoveMarker.startSmoothMove(); 105 | } 106 | } 107 | 108 | @Override 109 | public void destroySmooth() { 110 | if (smoothMoveMarker != null) { 111 | smoothMoveMarker.stopMove(); 112 | smoothMoveMarker.destroy(); 113 | mPKListLatLngContainer = null; 114 | smoothMoveMarker = null; 115 | } 116 | } 117 | 118 | @Override 119 | public void changSpeed(int totalDuration) { 120 | smoothMoveMarker.setTotalDuration(totalDuration); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/smooth/ISmooth.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.smooth; 2 | 3 | 4 | import pk.com.lib.map.MapResource; 5 | import pk.com.lib.map.modle.PKListLatLngContainer; 6 | 7 | /** 8 | * Created by pukai on 16/12/21. 9 | */ 10 | public abstract class ISmooth extends MapResource { 11 | /** 12 | * 开始平滑移动 13 | * 14 | * @param fiveListLatLngContainer 点集合 15 | * @param fiveSmoothListener 移动的事件监听 16 | */ 17 | public abstract void initSmooth(int color, int totalDuration, PKListLatLngContainer fiveListLatLngContainer, PKSmoothListener fiveSmoothListener); 18 | 19 | /** 20 | * 停止平滑移动 21 | */ 22 | public abstract void stopSmooth(); 23 | 24 | /** 25 | * 重新开始平滑移动 与@link stopSmooth 相对 26 | */ 27 | public abstract void reStartSmooth(); 28 | 29 | /** 30 | * 开始平滑移动 31 | */ 32 | public abstract void startSmooth(); 33 | 34 | /** 35 | * 开始平滑移动 36 | */ 37 | public abstract void destroySmooth(); 38 | 39 | public abstract void changSpeed(int totalDuration); 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/smooth/PKSmoothListener.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.smooth; 2 | 3 | 4 | import pk.com.lib.map.modle.PKLatLng; 5 | 6 | /** 7 | * Created by pukai on 16/12/27. 8 | */ 9 | public interface PKSmoothListener { 10 | /** 11 | * 平滑移动过程中的回调 12 | * 13 | * @param distance 移动的当前距离 14 | * @param fiveLatLng 当前移动到的点 15 | */ 16 | void move(double distance, PKLatLng fiveLatLng, int index); 17 | 18 | /** 19 | * 平滑移动结束后的回调 20 | */ 21 | void smoothFinish(); 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/trace/AMapTrace.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.trace; 2 | 3 | import android.content.Context; 4 | 5 | import com.amap.api.maps.AMap; 6 | import com.amap.api.maps.model.LatLng; 7 | import com.amap.api.trace.LBSTraceClient; 8 | import com.amap.api.trace.TraceListener; 9 | import com.amap.api.trace.TraceLocation; 10 | 11 | import java.util.List; 12 | 13 | import pk.com.lib.map.modle.PKListLatLngContainer; 14 | import pk.com.lib.map.modle.PKListTraceLocationContainer; 15 | 16 | /**

    高德地图轨迹纠偏的具体实现

    17 | * Created by pukai on 16/12/22. 18 | */ 19 | public class AMapTrace extends ITrace{ 20 | 21 | //private TraceOverlay mTraceOverlay; 22 | private LBSTraceClient mTraceClient; 23 | private int mSequenceLineID = 1000; 24 | private int mCoordinateType = LBSTraceClient.TYPE_AMAP; 25 | 26 | private PKTraceListener mPKTraceListener; 27 | 28 | public AMapTrace(AMap aMap, Context context){ 29 | initMapResource(aMap,context); 30 | } 31 | @Override 32 | public void startTrace(PKListTraceLocationContainer fiveListTraceLocationContainer, PKTraceListener fiveTraceListener) { 33 | mPKTraceListener = fiveTraceListener; 34 | if(fiveListTraceLocationContainer ==null){ 35 | if(mPKTraceListener!=null){ 36 | mPKTraceListener.onFinished(0,null,0,0); 37 | } 38 | return; 39 | } 40 | List traceLocations = fiveListTraceLocationContainer.getaMaplist(); 41 | if(traceLocations==null||traceLocations.isEmpty()){ 42 | if(mPKTraceListener!=null){ 43 | mPKTraceListener.onFinished(0,null,0,0); 44 | } 45 | return; 46 | } 47 | if(mTraceClient==null){ 48 | mTraceClient = new LBSTraceClient(mContext); 49 | } 50 | mTraceClient.queryProcessedTrace(mSequenceLineID,traceLocations,mCoordinateType,mTraceListener); 51 | } 52 | private TraceListener mTraceListener = new TraceListener() { 53 | @Override 54 | public void onRequestFailed(int lineID, String errorInfo) { 55 | if(mPKTraceListener!=null){ 56 | mPKTraceListener.onRequestFailed(lineID,errorInfo); 57 | } 58 | } 59 | 60 | @Override 61 | public void onTraceProcessing(int lineID, int index, List list) { 62 | if(mPKTraceListener!=null){ 63 | PKListLatLngContainer fiveListLatLngContainer = new PKListLatLngContainer(); 64 | fiveListLatLngContainer.setaMaplist(list); 65 | mPKTraceListener.onTraceProcessing(lineID,index,fiveListLatLngContainer); 66 | } 67 | } 68 | 69 | @Override 70 | public void onFinished(int lineID, List list, int distance, int waitingTime) { 71 | if(mPKTraceListener!=null) { 72 | PKListLatLngContainer fiveListLatLngContainer = new PKListLatLngContainer(); 73 | fiveListLatLngContainer.setaMaplist(list); 74 | mPKTraceListener.onFinished(lineID,fiveListLatLngContainer,distance,waitingTime); 75 | } 76 | } 77 | }; 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/trace/ITrace.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.trace; 2 | 3 | 4 | import pk.com.lib.map.MapResource; 5 | import pk.com.lib.map.modle.PKListTraceLocationContainer; 6 | 7 | /** 8 | * Created by pukai on 16/12/21. 9 | */ 10 | public abstract class ITrace extends MapResource { 11 | /** 12 | * 开始轨迹纠偏 13 | * @param fiveListTraceLocationContainer 轨迹的点集合 14 | * @param fiveTraceListener 轨迹纠偏的回调 15 | */ 16 | abstract void startTrace(PKListTraceLocationContainer fiveListTraceLocationContainer, PKTraceListener fiveTraceListener); 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/pk/com/lib/map/trace/PKTraceListener.java: -------------------------------------------------------------------------------- 1 | package pk.com.lib.map.trace; 2 | 3 | 4 | import pk.com.lib.map.modle.PKListLatLngContainer; 5 | 6 | /** 7 | * Created by pukai on 16/12/26. 8 | */ 9 | public interface PKTraceListener { 10 | /** 11 | * 轨迹纠偏失败的回调 12 | * 13 | * @param lineID 路线的id 14 | * @param errorInfo 错误信息 15 | */ 16 | void onRequestFailed(int lineID, String errorInfo); 17 | 18 | /** 19 | * 轨迹纠偏过程中的回调 返回当前已经纠偏过的点和线路id 20 | * 21 | * @param lineID 线路id 22 | * @param index 已纠偏的点的数目 23 | * @param fiveListLatLngContainer 点集合 24 | */ 25 | void onTraceProcessing(int lineID, int index, PKListLatLngContainer fiveListLatLngContainer); 26 | 27 | /** 28 | * 轨迹纠偏完成的回调 29 | * 30 | * @param lineID 线路的id 31 | * @param fiveListLatLngContainer 纠偏后的所有的点集合 32 | * @param distance 距离 33 | * @param waitingTime 等待时间 34 | */ 35 | void onFinished(int lineID, PKListLatLngContainer fiveListLatLngContainer, int distance, int waitingTime); 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/jniLibs/arm64-v8a/libgdinamapv4sdk752.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/jniLibs/arm64-v8a/libgdinamapv4sdk752.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/arm64-v8a/libgdinamapv4sdk752ex.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/jniLibs/arm64-v8a/libgdinamapv4sdk752ex.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libgdinamapv4sdk752.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/jniLibs/armeabi/libgdinamapv4sdk752.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libgdinamapv4sdk752ex.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/jniLibs/armeabi/libgdinamapv4sdk752ex.so -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_car_location_bkg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/res/drawable-xhdpi/btn_car_location_bkg.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_car_location_exception.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/res/drawable-xhdpi/btn_car_location_exception.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_car_location_exception_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/res/drawable-xhdpi/btn_car_location_exception_pressed.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_car_location_moving.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/res/drawable-xhdpi/btn_car_location_moving.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_car_location_moving_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/res/drawable-xhdpi/btn_car_location_moving_pressed.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_car_location_parking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/res/drawable-xhdpi/btn_car_location_parking.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/btn_car_location_parking_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/res/drawable-xhdpi/btn_car_location_parking_pressed.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_car.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/res/drawable-xhdpi/icon_car.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/icon_end.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/MapLibForApp/c8bad60b39adeec199ec6a85023f45b9ab3eac24/app/src/main/res/drawable-xhdpi/icon_end.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_car_exception_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_car_moving_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_car_parking_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_business.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 21 | 22 |