从未调用过HereMap PositioningListener [英] HereMap PositioningListener Was Never Called

查看:105
本文介绍了从未调用过HereMap PositioningListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 HereMap 上还很陌生.我花了一些时间,但仍然看不到这是怎么回事.我用以下代码初始化了HereMap.

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());
            }
        }
    });    

我像下面的代码一样声明了我的positionListener:

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();
        }
    }

我非常确定地图已经成功初始化,gmMapFragment.init(..),因为我可以在屏幕上看到地图.如果我使用从Google地图工具获得的坐标,甚至可以在此地图上绘制路线.但是我确实需要这里地图来获取我的当前位置,因为我们需要逐个进行3D.

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.

但是onPositionUpdated(...)从未被调用.我是否需要做其他任何事情才能使其正常工作?我认为将侦听器添加到PositionManager中就足够了.

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.

推荐答案

摘要:您可以尝试收听"OnPositionChangedListener#onPositionFixChanged(LocationMethod方法,LocationStatus状态)",看看是否有解决方案.另外,您可以检查'gmPositioningManager.start'的返回值,如果有问题,它可以返回false.您也可以使用"getLocationStatus(LocationMethod方法)"手动检查"LocationStatus".此页面可能对您有所帮助:基本定位

Summary: You can try listening to 'OnPositionChangedListener#onPositionFixChanged(LocationMethod method, LocationStatus status)' to see if you have a fix. Also, you can check the return value of 'gmPositioningManager.start', it can return false if there is a problem. You can manually check the 'LocationStatus' using 'getLocationStatus(LocationMethod method)' as well. This page may be helpful to you: Basic Positioning

这篇关于从未调用过HereMap PositioningListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆