通过指定边界框实现来下载地图

时间:2018-12-09 11:26:09

标签: android maps here-api

我已经阅读了高级用户指南,我们可以使用MapDataPrefetcher下载少量地图。我使用Mapfragment在我的应用程序中显示地图,它说MapEngine是通过使用MapFragment自动初始化的。

问题是我不明白如何应用这些方法以及我在哪里需要初始化下载边界框本身的请求。在用户指南中不清楚。

如果这里有人可以帮助我解决该问题或发送实施示例,我将非常感谢!

这是我对地图和地图片段的初始化方法

 private void initialize() {
    setContentView(R.layout.activity_main);

    // Search for the map fragment to finish setup by calling init().
    //  mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
    mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
    mLocationInfo = (TextView) findViewById(R.id.textViewLocationInfo);
    mapFragment.setRetainInstance(false);
    // Set up disk cache path for the map service for this application
    // It is recommended to use a path under your application folder for storing the disk cache
    boolean success = com.here.android.mpa.common.MapSettings.setIsolatedDiskCacheRootPath(
            getApplicationContext().getExternalFilesDir(null)+File.separator + ".here-maps",
            "com.example.andrey88.MapService"); /* ATTENTION! Do not forget to update {YOUR_INTENT_NAME} */
    if (!success) {
        Toast.makeText(getApplicationContext(), "Unable to set isolated disk cache path.", Toast.LENGTH_LONG);
    } else {
        mapFragment.init(new OnEngineInitListener() {
            @Override
            public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                if (error == OnEngineInitListener.Error.NONE) {
                    // retrieve a reference of the map from the map fragment
                    map = mapFragment.getMap();
                    // Set the map center to the Ruppin region (no animation)
                    map.setCenter(new GeoCoordinate(32.343099, 34.911272, 0.0), Map.Animation.NONE);
                    // Set the zoom level
                    map.setZoomLevel(17.8);


                    map.setMapScheme(Map.Scheme.PEDESTRIAN_DAY);
                    map.setLandmarksVisible(false);
                    map.setProjectionMode(Map.Projection.MERCATOR);
                    map.getPedestrianFeaturesVisible();



                    // position of user
                    map.addTransformListener(MainActivity.this);
                    mPositioningManager = PositioningManager.getInstance();

                    // check source of getting geo location
                    mHereLocation = LocationDataSourceHERE.getInstance(
                            new StatusListener() {
                                @Override
                                public void onOfflineModeChanged(boolean offline) {
                                    // called when offline mode changes
                                }

                                @Override
                                public void onAirplaneModeEnabled() {
                                    // called when airplane mode is enabled
                                }

                                @Override
                                public void onWifiScansDisabled() {
                                    // called when Wi-Fi scans are disabled
                                }

                                @Override
                                public void onBluetoothDisabled() {
                                    // called when Bluetooth is disabled
                                }

                                @Override
                                public void onCellDisabled() {
                                    // called when Cell radios are switch off
                                }

                                @Override
                                public void onGnssLocationDisabled() {
                                    // called when GPS positioning is disabled
                                }

                                @Override
                                public void onNetworkLocationDisabled() {
                                    // called when network positioning is disabled
                                }

                                @Override
                                public void onServiceError(StatusListener.ServiceError serviceError) {
                                    // called on HERE service error
                                }

                                @Override
                                public void onPositioningError(PositioningError positioningError) {
                                    // called when positioning fails
                                }

                                @Override
                                public void onWifiIndoorPositioningNotAvailable() {
                                    // called when running on Android 9.0 (Pie) or newer
                                }
                            });

                    if (mHereLocation == null) {
                        Toast.makeText(MainActivity.this, "LocationDataSourceHERE.getInstance(): failed, exiting", Toast.LENGTH_LONG).show();
                        finish();
                    }
                    mPositioningManager.setDataSource(mHereLocation);
                    mPositioningManager.addListener(new WeakReference<PositioningManager.OnPositionChangedListener>(MainActivity.this));


                    // Create a custom marker image
                    com.here.android.mpa.common.Image myImage = new com.here.android.mpa.common.Image();
                    try {myImage.setImageResource(R.drawable.marker_round);
                    } catch (IOException e) {
                        finish();
                    }
                    initMarkers(myImage);

                    createPolygon();

                    mapFragment.getMapGesture().addOnGestureListener(new MapGesture.OnGestureListener() {
                        @Override
                        public void onPanStart() {
                        }

                        @Override
                        public void onPanEnd() {
                        }

                        @Override
                        public void onMultiFingerManipulationStart() {

                        }

                        @Override
                        public void onMultiFingerManipulationEnd() {

                        }

                        @Override
                        public boolean onMapObjectsSelected(List<ViewObject> list) {
                            return false;
                        }

                        @Override
                        public boolean onTapEvent(PointF pointF) {
                            return false;
                        }

                        @Override
                        public boolean onDoubleTapEvent(PointF pointF) {
                            return false;
                        }

                        @Override
                        public void onPinchLocked() {

                        }

                        @Override
                        public boolean onPinchZoomEvent(float v, PointF pointF) {
                            return false;
                        }

                        @Override
                        public void onRotateLocked() {

                        }

                        @Override
                        public boolean onRotateEvent(float v) {
                            return false;
                        }

                        @Override
                        public boolean onTiltEvent(float v) {
                            return false;
                        }

                        @Override
                        public boolean onLongPressEvent(PointF pointF) {
                            return false;
                        }

                        @Override
                        public void onLongPressRelease() {

                        }

                        @Override
                        public boolean onTwoFingerTapEvent(PointF pointF) {
                            return false;
                        }
                    }, 0, false);
                    if (mPositioningManager.start(PositioningManager.LocationMethod.GPS_NETWORK_INDOOR)) {
                        mapFragment.getPositionIndicator().setVisible(true);
                    } else {
                        Toast.makeText(MainActivity.this, "PositioningManager.start: failed, exiting", Toast.LENGTH_LONG).show();
                        finish();
                    }

                }
                else {
                    Log.d("errorTag",error.name());
                    onDestroy();

                }
            }
        });

    }
}

1 个答案:

答案 0 :(得分:0)

MapEngine必须先初始化,然后才能使用。它应该在主线程中完成。使用AndroidXMapFragment为您的应用程序自动初始化MapEngine。 AndroidXMapFragment是片段类应用程序,可以在活动中用作地图显示的UI模块。但是,如果您的应用程序不使用AndroidXMapFragment类,则应用程序应在使用任何HERE API之前直接初始化MapEngine。您可以通过调用MapEngine.init(ApplicationContext,OnEngineInitListener)来做到这一点,如下所示:

MapEngine mapEngine = MapEngine.getInstance(); ApplicationContext appContext = new ApplicationContext(context); mapEngine.init(appContext, new OnEngineInitListener() {   @Override   public void onEngineInitializationCompleted(Error error) {
    if (error == OnEngineInitListener.Error.NONE) {
      // Post initialization code goes here
    } else {
      // handle factory initialization failure
    }   } });