使用HERE API取得我的位置(Wifi)时出现问题[更新] [英] Problems using HERE API to get my position (Wifi) [UPDATED]

查看:77
本文介绍了使用HERE API取得我的位置(Wifi)时出现问题[更新]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在平板电脑上安装了HERE测试产品(这是一台旧的Android 5.1平板电脑,没有GPS或蜂窝数据,只有Wifi上网),并且可以很好地(大约)使用Wifi定位我的位置.

I installed the HERE test product on my tablet (it's an old Android 5.1 tablet without GPS or Cellular data, just Wifi) and it worked well to (approximately) give my position using Wifi.

所以我试图在我的应用程序中对其进行编程.

So I am attempting to program the same in my app.

下载了HERE API,获得了我应用名称的免费增值许可,并在清单中输入以下行:

Downloaded the HERE API, got a freemium license for my app name, input the lines in my manifest:

<meta-data
    android:name="com.here.android.maps.appid"
    android:value="itkC4uIay69MTXXXXXXX" />
<meta-data
    android:name="com.here.android.maps.apptoken"
    android:value="NdT8laoCmRysyh8XXXXXXX" />

在我的构建中包含了HERE-sdk,并且我的代码也可以正常编译.

Included the HERE-sdk in my build, and my Code compiles just fine.

我的MainActivity.onCreate()中有代码[我已添加代码以按照下面的HERE支持的建议来初始化地图引擎]:

I have code in my MainActivity.onCreate() :

    MapEngine.getInstance().init(this, new OnEngineInitListener() {
        @Override
        public void onEngineInitializationCompleted(Error error) {
            if (error == Error.NONE) {
                Logger.i(Tags.POSITION, "correctly started map engine");
                PositioningManager pm = PositioningManager.getInstance();
                PositioningManager.LocationStatus  ls = pm.getLocationStatus(PositioningManager.LocationMethod.GPS_NETWORK);
                if (ls ==  PositioningManager.LocationStatus.AVAILABLE) {
                    Logger.i(Tags.POSITION, "Positioning is available");
                } else {
                    Logger.w(Tags.POSITION, "Positioning not available right now " + ls.toString());
                }
                pm.start(PositioningManager.LocationMethod.GPS_NETWORK);
            } else {
                Logger.i(Tags.POSITION, "Problem setting up map engine: " + error);
            }
        }
    });

然后,我每分钟在计时器上运行一次代码以检查我的当前位置:

Then I have code running once per minute on a timer to check my current position:

        GeoPosition pos = PositioningManager.getInstance().getPosition();
        if (pos == null) {
            Log.w("Positioning", "GeoPosition is Null");
        } else {
            GeoCoordinate coord = pos.getCoordinate();
            Logger.i("Positioning", "Location: Latitude = " + coord.getLatitude() + ", Longitude = " + coord.getLongitude());
            Logger.i("Positioning", "Accuracy = " + pos.getLatitudeAccuracy() + ", " + pos.getLongitudeAccuracy());
        }

当我跑步时,我会得到这样的日志:

When I run I get logs like this:

2019-01-27 11:49:31.960 30112-30112/com.company.app I/: [main] INFO  Positioning: correctly started map engine
2019-01-27 11:49:31.961 30112-30112/com.company.app W: [main] WARN  Positioning: Positioning not available right now OUT_OF_SERVICE

然后,每分钟一次

2019-01-27 11:50:30.850 30112-30343/com.company.app W/: [Timer-2] WARN  Positioning: GeoPosition is Null

在平板电脑的设置"中,虽然显示最近没有应用请求位置",但位置"已打开.

In "Settings" on the tablet "Location" is turned "On" though it says "No apps have requested Location recently"

日志不包含错误或警告,所有权限均在清单中请求

The logs contain no Errors or warnings, all permissions are requested in the Manifest

最糟糕的是我的简单测试应用程序(在下面的评论中提到),在我添加了MapEngine的初始化之后,现在可以使用了.要回答HERE的问题,我现在真的对使用映射不感兴趣,我只想获取当前的经度和纬度以帮助丢失平板电脑.

The worst thing is my simple test app (mentioned in my comment below), now works after I added in the initializaion of the MapEngine. To answer HERE's question, I really am not interested in using mapping just now, I only want to pull a current Longitude and Latitude to aid in finding my tablet if lost.

有人知道我在做什么错吗?

Anyone have a clue what I am doing wrong?

推荐答案

我有几个问题要问,关于这个问题的答案将帮助我们了解问题所在.

I have a few questions to ask, the answer on which will help us to understand what is going wrong.

  1. 您要显示地图还是仅使用PositioningManager?
  2. 如果仅使用PositionManager,是否首先初始化MapEngine?

如果不使用Map,则必须执行类似的操作,因为PositionManager不会初始化MapEngine本身.

If you don't use a Map, you have to do something like this since PositionManager doesn't initialize MapEngine itself.

ApplicationContext context = new ApplicationContext(getApplicationContext());
MapEngine.getInstance().init(context, new OnEngineInitListener() {

  @Override
  public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
    if (error == OnEngineInitListener.Error.NONE) {

    } else {

    }
  }
});

更新:github上还有另一个测试应用程序可能非常有用,没有使用地图,而是使用了位置管理器.希望这可以帮助! https://github.com/heremaps/这里是android-sdk-examples/tree/master/speed-limit-watcher

Update: There is another test application on github that might be quite useful, no map using but position manager being used. Hope this helps! https://github.com/heremaps/here-android-sdk-examples/tree/master/speed-limit-watcher

这篇关于使用HERE API取得我的位置(Wifi)时出现问题[更新]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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