我现在手头有一个移动地图包(.mmpk),我想在我要制作的应用程序中执行路由。但是,我不知道如何在mmpk内部加载运输网络。有人能给我一些建议吗?谢谢。
P.S。该应用程序将使用Android Studio进行,我使用Java来完成它。
P.S.S。路由网络数据位于地理数据库
中以下是代码,请看一下:
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;
import com.esri.arcgisruntime.loadable.LoadStatus;
import com.esri.arcgisruntime.mapping.MobileMapPackage;
import com.esri.arcgisruntime.mapping.view.MapView;
import java.io.File;
public class ActivityElderly extends AppCompatActivity {
private static final String TAG = "MMPK";
private static final String FILE_EXTENSION = ".mmpk";
private static File extStorDir;
private static String extSDCardDirName;
private static String filename;
private static String mmpkFilePath;
private MapView mMapView;
private MobileMapPackage mapPackage;
String[] reqPermission = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
private int requestCode = 2;
private static String createMobileMapPackageFilePath(){
return extStorDir.getAbsolutePath() + File.separator + extSDCardDirName + File.separator + filename + FILE_EXTENSION;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from new_activity.xml
setContentView(R.layout.map_elderly);
// get sdcard resource name
extStorDir = Environment.getExternalStorageDirectory();
// get the directory
extSDCardDirName = this.getResources().getString(R.string.config_data_sdcard_offline_dir);
// get mobile map package filename
filename = this.getResources().getString(R.string.config_mmpk_name);
// create the full path to the mobile map package file
mmpkFilePath = createMobileMapPackageFilePath();
// retrieve the MapView from layout
mMapView = (MapView) findViewById(R.id.mapView);
if(ContextCompat.checkSelfPermission(ActivityElderly.this, reqPermission[0]) == PackageManager.PERMISSION_GRANTED){
loadMobileMapPackage(mmpkFilePath);
}else{
// request permission
ActivityCompat.requestPermissions(ActivityElderly.this, reqPermission, requestCode);
}
}
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults){
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
loadMobileMapPackage(mmpkFilePath);
}else{
// report to user that permission was denied
Toast.makeText(ActivityElderly.this, getResources().getString(R.string.location_permission_denied),
Toast.LENGTH_SHORT).show();
}
}
private void loadMobileMapPackage(String mmpkFile){
//[DocRef: Name=Open Mobile Map Package-android, Category=Work with maps, Topic=Create an offline map]
// create the mobile map package
mapPackage = new MobileMapPackage(mmpkFile);
// load the mobile map package asynchronously
mapPackage.loadAsync();
// add done listener which will invoke when mobile map package has loaded
mapPackage.addDoneLoadingListener(new Runnable() {
@Override
public void run() {
// check load status and that the mobile map package has maps
if(mapPackage.getLoadStatus() == LoadStatus.LOADED && mapPackage.getMaps().size() > 0){
// add the map from the mobile map package to the MapView
mMapView.setMap(mapPackage.getMaps().get(0));
}else{
// Log an issue if the mobile map package fails to load
Log.e(TAG, mapPackage.getLoadError().getMessage());
}
}
});
//[DocRef: END]
}
@Override
protected void onPause(){
super.onPause();
mMapView.pause();
}
@Override
protected void onResume(){
super.onResume();
mMapView.resume();
}
答案 0 :(得分:0)
如果您正在寻找一种方法来准备包裹,那么请租用一下那个http://pro.arcgis.com/en/pro-app/tool-reference/data-management/create-mobile-map-package.htm#GUID-9116AC0F-08E1-4B55-965D-123F01262A53
的工具如果您正在寻找如何创建RouteTask,请查看文档https://developers.arcgis.com/android/latest/guide/find-a-route.htm
如果您正在寻找从已准备好的离线软件包加载网络数据的方法,那么请查看github上的示例https://github.com/Esri/arcgis-runtime-samples-android/tree/master/java/mobile-map-search-and-route
简而言之,您只需获取包含网络数据集的任何地图,并在RouteTask中使用它。
ArcGISMap map = mMobileMapPackage.getMaps().get(0);
//if map contains transport network setup route task
if (map.getTransportationNetworks().size() > 0) {
mRouteTask = new RouteTask(this, map.getTransportationNetworks().get(0));
}