HereMap PositioningListener Was Never Called

夙愿已清 提交于 2019-12-25 10:45:47

问题


I am pretty new on HereMap. I'd spent some time but I still cannot see what's wrong on this. I had the HereMap initialized with the following codes.

    MapFragment gmMapFragment = ...

    gmMapFragment.init(Common.main_activity, new OnEngineInitListener() {
        @Override
        public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
            if (error == OnEngineInitListener.Error.NONE) {

                gmMapFragment.getMapGesture().addOnGestureListener(gestureListener);

                gmMap = gmMapFragment.getMap();

                // Set the map center to the Vancouver region (no animation)
                gmMap.setCenter(new GeoCoordinate(tw.latitude, tw.longitude, 0.0),
                    Map.Animation.NONE);
                // Set the zoom level to the average between min and max
                gmMap.setZoomLevel((gmMap.getMaxZoomLevel() + gmMap.getMinZoomLevel()) / 2);

                gmMap.setProjectionMode(Map.Projection.MERCATOR);

                gmMap.getPositionIndicator().setVisible(true);

                gmPositioningManager = PositioningManager.getInstance();
                gmPositioningManager.addListener(new WeakReference<>(positionListener));

                gmPositioningManager.start(PositioningManager.LocationMethod.GPS_NETWORK);

            } else {
                System.out.println("ERROR: Cannot initialize Map Fragment,"
                    + error.name() + "," + error.getDetails() + "," +error.getStackTrace());
            }
        }
    });    

and I had my positionListener declared like the codes below:

private PositioningManager.OnPositionChangedListener positionListener = new
    PositioningManager.OnPositionChangedListener() {

    public void onPositionUpdated(PositioningManager.LocationMethod method,
                                  GeoPosition position, boolean isMapMatched) {

        // set the center only when the app is in the foreground
        // to reduce CPU consumption
        if (!paused) {
            gmGeoCoordinate = position.getCoordinate();
        }
    }

I am very sure that the map has been initialized successfully, gmMapFragment.init(..), because I could see the map on the screen. If I use the coordinate that I got from Google map tools, I could even draw the route on the here map. But I do need the here map to get the current location for me because we need to do the 3D turn-by-turn.

But the onPositionUpdated(...) never got called. Did I need to do anything else make it work? I thought that adding the listener to the PositionManager is good enough.

来源:https://stackoverflow.com/questions/43833725/heremap-positioninglistener-was-never-called

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!