zoukankan      html  css  js  c++  java
  • app获取定位

    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    if (location != null) {
                        msg = msg + "
    位置(onLocationChanged): " + location.getLongitude() + "," + location.getLatitude();
                    } else {
                        msg = msg + "
    位置(onLocationChanged): location is null";
                    }
                    new SendMsgTask().execute();
                }
    
                @Override
                public void onStatusChanged(String provider, int status, Bundle extras) {
                }
    
                @Override
                public void onProviderEnabled(String provider) {
                    Location location = mLocationManager.getLastKnownLocation(provider);
                    if (location != null) {
                        msg = msg + "
    位置(onProviderEnabled): " + location.getLongitude() + "," + location.getLatitude();
                    } else {
                        msg = msg + "
    位置(onProviderEnabled): location is null";
                    }
                    new SendMsgTask().execute();
                }
    
                @Override
                public void onProviderDisabled(String provider) {
    
                }
            });

     这个位置的监听,即使页面跳转到其他页面,依然会保持监听,除非退出app

    在监听的过程中,消息栏一直会提示程序在使用定位功能

    不晓得为什么每次获取的位置都是null,即使加了监听也还是null

    provider = LocationManager.NETWORK_PROVIDER;
            location = mLocationManager.getLastKnownLocation(provider);
            
            if (location != null) {
                msg = msg + "
    位置(" + provider + "): " + location.getLongitude() + "," + location.getLatitude();
            } else {
                msg = msg + "
    位置(" + provider + "): location is null";
            }

     使用network的方式倒是成功过两次

  • 相关阅读:
    COGS 577 蝗灾 线段树+CDQ分治
    BZOJ 1305 二分+网络流
    BZOJ 1066 Dinic
    BZOJ 3544 treap (set)
    BZOJ 3940 AC自动机
    BZOJ 1503 treap
    BZOJ 3172 AC自动机
    BZOJ 2553 AC自动机+矩阵快速幂 (神题)
    BZOJ1901 ZOJ2112 线段树+treap (线段树套线段树)
    BZOJ 3196 线段树套平衡树
  • 原文地址:https://www.cnblogs.com/LcxSummer/p/13045169.html
Copyright © 2011-2022 走看看