简体   繁体   中英

Android/Java: How to install a package country offline in HereMap?

I try to download the packages that I need for using the map offline, but nothing happens.

3.x based Premium Edition
I trie many ways like this documentation of HereMap, like this ticket or this ticket but nothing works, nothing is firing the download functions.

Here is my code:

private final static String TAG = "HereMap";
    private ArrayList<MapPackage> currentInstalledMaps;
    private String currentInstalledMapsString;
    private MapLoader.Listener mapLoaderHandler = new MapLoader.Listener() {

        @Override
        public void onProgress(int progress) {
            Log.i(TAG, "Progress " + progress + "%");
         //   downloadProgressBar.setProgress(progress);
        }

        @Override
        public void onInstallationSize(long diskSize, long networkSize) {
            Log.i(TAG, "Map data require " + diskSize);
        }


        @Override
        public void onGetMapPackagesComplete(MapPackage rootMapPackage,
                                             MapLoader.ResultCode resultCode) {
            if (resultCode == MapLoader.ResultCode.OPERATION_SUCCESSFUL) {
                Log.i(TAG, "Map packages received successful: " + rootMapPackage.getTitle());

                currentInstalledMaps = new ArrayList<>(1);
                populateInstalledMaps(rootMapPackage);
            } else {
                Log.e(TAG, "Can't retrieve map packages: " + resultCode.name());
                Toast.makeText(HereMap.this,
                        "Error: " + resultCode.name(), Toast.LENGTH_SHORT).show();
                return;
            }

            StringBuilder sb = new StringBuilder();
            for (MapPackage pac : currentInstalledMaps) {
                sb.append(pac.getTitle());
                sb.append("\n");
            }

            currentInstalledMapsString = sb.toString();
        }

        private void populateInstalledMaps(MapPackage pac) {
            // only take installed root package, so if e.g. Germany is installed,
            // don't check for children states
            if (pac.getInstallationState() == MapPackage.InstallationState.INSTALLED) {
                Log.i(TAG, "Installed package found: " + pac.getTitle() + " id " + pac.getId());
                currentInstalledMaps.add(pac);
            } else if (pac.getChildren() != null && pac.getChildren().size() > 0) {
                for (MapPackage p : pac.getChildren()) {
                    populateInstalledMaps(p);
                }
            }
        }


        @Override
        public void onCheckForUpdateComplete(boolean updateAvailable, String currentMapVersion,
                                             String newestMapVersion, MapLoader.ResultCode resultCode) {
            Log.i(TAG, "onCheckForUpdateComplete. Update available: " + updateAvailable +
                    " current version: " + currentMapVersion);

            AlertDialog.Builder builder = new AlertDialog.Builder(
                    HereMap.this, R.style.AppCompatAlertDialogStyle);

            builder.setTitle("Map version checked");
            builder.setMessage("Current map version: " + currentMapVersion + "\n\n"
                    + (updateAvailable ? "Update found to " + newestMapVersion : "No update found")
                    + "\n\n" + "Installed maps:\n" + currentInstalledMapsString);
            builder.setNegativeButton("close", null);

            if (updateAvailable) {
                builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.i(TAG, "Update triggered");
                     /*   downloadProgressBar.setProgress(0);
                        downloadProgressBar.setVisibility(View.VISIBLE);*/
                        MapLoader.getInstance().performMapDataUpdate();
                    }
                });
            }

            builder.show();
        }


        @Override
        public void onPerformMapDataUpdateComplete(MapPackage rootMapPackage,
                                                   MapLoader.ResultCode resultCode) {
            Log.i(TAG, "onPerformMapDataUpdateComplete");
           // downloadProgressBar.setVisibility(View.INVISIBLE);
            String message;
            if (resultCode == MapLoader.ResultCode.OPERATION_SUCCESSFUL) {
                message = "Map updated successfully";
            } else {
                message = "Map update failed: " + resultCode.name();
            }
            Toast.makeText(HereMap.this, message, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onInstallMapPackagesComplete(MapPackage rootMapPackage,
                                                 MapLoader.ResultCode resultCode) {
           // downloadProgressBar.setVisibility(View.INVISIBLE);
            String message;
            if (resultCode == MapLoader.ResultCode.OPERATION_SUCCESSFUL) {
                message = "Maps installed successfully";
                Log.i(TAG, "Package is installed: "
                        + rootMapPackage.getId() + " " + rootMapPackage.getTitle());
                MapLoader.getInstance().getMapPackages();
            } else {
                message = "Map installation failed: " + resultCode.name();
                Log.e(TAG, "Failed to install package: "
                        + rootMapPackage.getId() + " " + rootMapPackage.getTitle());
            }
            Toast.makeText(HereMap.this, message, Toast.LENGTH_SHORT).show();
        }


        @Override
        public void onUninstallMapPackagesComplete(MapPackage rootMapPackage,
                                                   MapLoader.ResultCode resultCode) {
            Log.i(TAG, "onUninstallMapPackagesComplete");
            String message;
            if (resultCode == MapLoader.ResultCode.OPERATION_SUCCESSFUL) {
                message = "Maps removed successfully";
            } else {
                message = "Map removal failed: " + resultCode.name();
            }
            Toast.makeText(HereMap.this, message, Toast.LENGTH_SHORT).show();

            // update packages and get installation state
            MapLoader.getInstance().getMapPackages();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initialize();

        MapLoader mapLoader = MapLoader.getInstance();
          mapLoader.getMapPackages();

          mapLoader.addListener(mapLoaderHandler);

        List<Integer> downloadList = new ArrayList<>(1);
        downloadList.add(120002);    // Berlin/Brandenburg id 120002

        MapLoader.getInstance().installMapPackages(downloadList);
    }
...

EDIT:
newer 4.x Navigate Edition
Hi @datasun, I installed with the new SDK android heremap v3.19.4_227 with Offline Maps GitHub and it doesn't recognize lots of commands like: import com.here.sdk.mapview.MapView; in fact all the main import are not recognized com.here.sdk.mapview.x etc...

Here is are the main functions that cannot launch because of the import failure that is not present in the SDK:
屏幕1
屏幕2 屏幕3

Impossible to use it, and the documentation is very poor on that point.

Do you have any ideas?

The HERE SDK is available in different editions. Your link refers to the older 3.x based Premium Edition . It will not compile with the code needed for the newer 4.x Navigate Edition .

The offline maps feature shown in your code snippet is only working when you use the Navigate Edition . The documentation can be found here: https://developer.here.com/documentation/android-sdk-navigate

The OfflineMaps example app for this edition is available from here: https://github.com/heremaps/here-sdk-examples

As stated in the README, the offline maps feature and example app is exclusively available for the Navigate Edition . Other editions do not support it and hence, the code will not compile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM