相关疑难解决方法(0)

永远不会调用OnLocationChanged回调

我试图让用户使用当前位置LocationManager.我做了很多研究,似乎找不到任何有同样问题的人.该OnLocationChanged回调似乎永远不会被调用.下面是我的各种代码和logcat.

protected LocationListener locationListener;
protected LocationManager locationManager;
protected Context context;
Run Code Online (Sandbox Code Playgroud)

我的OnCreate()方法

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v(TAG, "IN ON CREATE");

    this.context = getActivity();

    registerLocationUpdates();
}
Run Code Online (Sandbox Code Playgroud)

我的registerLocationUpdates方法

void registerLocationUpdates() {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_LOW);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);

    locationManager = (LocationManager)getActivity().getSystemService(LOCATION_SERVICE);

    provider = locationManager.getBestProvider(criteria, true);

    // Cant get a hold of provider
    if (provider == null) {
        Log.v(TAG, "Provider is null");
        showNoProvider();
        return;
    } else {
        Log.v(TAG, "Provider: " + …
Run Code Online (Sandbox Code Playgroud)

android geolocation locationmanager

63
推荐指数
4
解决办法
8万
查看次数

如何检测用户何时打开/关闭gps状态?

我想阻止用户更改我的应用程序中的WiFi,GPS和加载设置.用户在运行我的应用程序时无需打开/关闭WiFi和GPS.(来自通知栏).是否BroadcastReceiver存在用于收听GPS开/关的功能?

gps android broadcastreceiver

19
推荐指数
5
解决办法
3万
查看次数

LocationCallback没有被调用

我正在使用FusedLocationProviderClient进行位置请求.我保留了一个计时器30秒,以检查在该时间范围内是否收到位置.代码如下:

 public void requestLocationUpdates() {
    initializeLocationRequest();
    mFusedLocationProviderClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);
    startTimer();
}

 private void initializeLocationRequest() {
    mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(mContext);
    mLocationRequest = new LocationRequest();
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    mLocationRequest.setInterval(5000);
    mLocationRequest.setFastestInterval(5000);

    mLocationCallback = new LocationCallback() {

        @Override
        public void onLocationResult(LocationResult locationResult) {
            synchronized (SilentCurrentLocationProvider.this) {
                super.onLocationResult(locationResult);
                Location location = locationResult.getLastLocation();
        }
    };
}

  private void startTimer() {
    if (mTimeout < 1) {
        mTimeout = mDefaultTimeout;
    }
    mTimer = new Timer();   
    mTimer.schedule(new LocationTimer(), mTimeout * 1000);
}
Run Code Online (Sandbox Code Playgroud)

在少数设备上,位置不会到来.在进一步调试时,我发现正在创建LocationRequestLocationCallback,但它没有进入onLocationResult()方法.

由于这是实时产品的一部分,因此很难在每台设备上进行调试.即使我尝试重新启动手机,但它无法正常工作.用户尝试了其他应用程序,如Ola和位置即将到来. …

android google-location-services fusedlocationproviderclient

15
推荐指数
2
解决办法
2174
查看次数

如何检查GPS是否已禁用Android

我在MainActivity中有两个文件MainActivity.java和HomeFragment.java从HomeFragment调用一个函数,该函数要求用户打开手机上的位置服务.问题是即使用户已经打开了位置功能,仍然会调用该功能.有没有办法我可以这样做只有当位置功能关闭时才启动HomeFragment中的功能.

HomeFragment.java

public static void displayPromptForEnablingGPS(
        final Activity activity)
{
    final AlertDialog.Builder builder =
            new AlertDialog.Builder(activity);
    final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
    final String message = "Enable either GPS or any other location"
            + " service to find current location.  Click OK to go to"
            + " location services settings to let you do so.";


    builder.setMessage(message)
            .setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface d, int id) {
                            activity.startActivity(new Intent(action));
                            d.dismiss();
                        }
                    });

    builder.create().show();
}
Run Code Online (Sandbox Code Playgroud)

MainActivity.java

public void showMainView() {
    HomeFragment.displayPromptForEnablingGPS(this);
} …
Run Code Online (Sandbox Code Playgroud)

java gps android function

13
推荐指数
1
解决办法
3万
查看次数

我怎样才能让谷歌地图api v2直接进入我的位置

我是一个真正的谷歌地图API菜鸟,所以任何帮助表示赞赏.我想在这里看到的是,当我打开我的应用程序时,相机需要直接移动到我当前的位置并放置蓝点.我该如何设法做到这一点?

我已经制作了一个示例代码,以便每个人都能理解它并在需要时实现它们的代码:

GoogleMap map = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.general_map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);

if( helper.isGPSEnabled() ){
    map.move... // move directly to my current position
}
Run Code Online (Sandbox Code Playgroud)

请帮忙...

camera android move google-maps-android-api-2

6
推荐指数
2
解决办法
2万
查看次数

i showed prompt to user to enable gps settings,but how can i check user really enabled the gps location on his phone?

I showed prompt to user to enable gps settings,but how can I check user really enabled the gps location on his phone?

private static void showGPSDisabledAlertToUser() {
        // TODO Auto-generated method stub
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ChatSDK.getSDKInstance().activity);
        alertDialogBuilder
                .setMessage(
                        "GPS is disabled in your device. Would you like to enable it?")
                .setCancelable(false)
                .setPositiveButton("Goto Settings Page To Enable GPS",

                new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                Intent callGPSSettingIntent = new Intent(
                                        android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                ChatSDK.getSDKInstance().activity.startActivity(callGPSSettingIntent);
                            }
                        });
//      alertDialogBuilder.setNegativeButton("Cancel",
// …
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
1
解决办法
3174
查看次数

检查用户设备的 GPS 是否开启

我正在使用 jQuery Mobile 和 PHP 开发一个应用程序。我没有使用 Phonegap 或其他框架。我需要找到用户的geolocation. 如果用户设备的 GPS 关闭,我将无法获取位置。现在我需要查找用户设备的 GPS 是否打开或关闭。

这就是我现在使用的。

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  var lat=position.coords.latitude;
  var long=position.coords.longitude;
}
Run Code Online (Sandbox Code Playgroud)

javascript php gps jquery-mobile

4
推荐指数
1
解决办法
1万
查看次数

Android - 如果启用或禁用GPS,有没有办法收听

我写这段代码来接收位置更新 -

PendingIntent launchIntent = PendingIntent.getBroadcast(context, 5000, intent, 0);
manager.requestLocationUpdates(selectProvider(), 0, 0, launchIntent);
Run Code Online (Sandbox Code Playgroud)

如果可用,我选择gps提供商,否则选择网络提供商.如果以后启用它,有没有办法可以切换回gps?

启用或禁用gps提供程序时,系统是否广播了意图?我可以为此设置一个监听器吗?

gps android

3
推荐指数
2
解决办法
6446
查看次数

为什么检查GPS_PROVIDER isProviderEnabled总是"假"?

我无法确定是GPS打开还是关闭,isProviderEnabled总是"假"但GPS打开.

public abstract class BaseGPSActivity extends AppCompatActivity{

  @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Log.v(TAG, " GPS is enabled: "+isGPSEnabled()))
Run Code Online (Sandbox Code Playgroud)
 public boolean isGPSEnabled(){
        String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        if(provider != null)
            Log.v(TAG, " Location providers: "+provider);
        return mLocationManager!=null && mLocationManager.isProviderEnabled( LocationManager.GPS_PROVIDER );
    }
Run Code Online (Sandbox Code Playgroud)

输出是:

V/BaseGPSActivity:  Location providers: network

V/BaseGPSActivity:  GPS is enabled:  false
Run Code Online (Sandbox Code Playgroud)

gps android

3
推荐指数
1
解决办法
1237
查看次数