Kibi
Kibi

Reputation: 2060

Problems using HERE API to get my position (Wifi) [UPDATED]

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.

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" />

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

I have code in my MainActivity.onCreate() [EDIT I have added in code to initialize the map engine as recommended by HERE support below]:

    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

Then, once per minute

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

[EDIT] 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?

Upvotes: 2

Views: 982

Answers (1)

user3505695
user3505695

Reputation:

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

  1. Do you want to show a map or just using PositioningManager?
  2. If using PositionManager only, do you initialize MapEngine initially?

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 {

    }
  }
});

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

Upvotes: 1

Related Questions