onLocationChanged未在IndoorAtlas位置经理

时间:2017-04-07 08:07:55

标签: java android geolocation on-location-changed

测试时我能够从IALocationListener中的onStatusChanged接收更新,但是没有调用onLocationChanged。关于这是为什么的任何想法?

我已按照IndoorAtlas(http://docs.indooratlas.com/android/dev-guide/getting-user-location.html)的说明以及YouTube上的视频(https://www.youtube.com/watch?v=2EXkV4xL5rg),但仍无法获取该位置。

我是否必须在我所绘制的区域内,或者无论我在哪里都应该阅读该位置?

package com.bignerdranch.android.indoormapping;

import android.Manifest;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.os.Bundle;
import android.util.Log;

import com.indooratlas.android.sdk.IALocation;
import com.indooratlas.android.sdk.IALocationListener;
import com.indooratlas.android.sdk.IALocationManager;
import com.indooratlas.android.sdk.IALocationRequest;

public class MappingActivity extends FragmentActivity {

    private final int CODE_PERMISSIONS = 0;
    private IALocationManager mIALocationManager;
    private static final String TAG = "LocateActivity";

    private IALocationListener mIALocationListener = new IALocationListener() {
        @Override
        public void onLocationChanged(IALocation iaLocation) {
            Log.d(TAG, "Latitude: " + iaLocation.getLatitude());
        }

        @Override
        public void onStatusChanged(String s, int i, Bundle bundle) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mapping);

        mIALocationManager = IALocationManager.create(this);



        // request permissions for coarse location and Wifi
        String[] neededPermissions = {
                Manifest.permission.CHANGE_WIFI_STATE,
                Manifest.permission.ACCESS_WIFI_STATE,
                Manifest.permission.ACCESS_COARSE_LOCATION
        };
        ActivityCompat.requestPermissions( this, neededPermissions, CODE_PERMISSIONS );

        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragment_cont);

        if(fragment == null) {
            fragment = new MappingFragment();
            fm.beginTransaction()
                    .add(R.id.fragment_cont, fragment)
                    .commit();
        }
    }

    // handle any permissions that are denied
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    @Override
    public void onResume() {
        super.onResume();
        mIALocationManager.requestLocationUpdates(IALocationRequest.create(), mIALocationListener);
    }

    @Override
    public void onPause() {
        super.onPause();
        mIALocationManager.removeLocationUpdates(mIALocationListener);
    }
}

1 个答案:

答案 0 :(得分:0)

Here IndoorAtlas已经提供了一些SDK的代码示例。你应该能够找到问题。