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的方式倒是成功过两次

  • 相关阅读:
    Xamarin.Forms之界面设计原则
    Xamarin.Forms之异步
    Xamarin Studio常见问题
    Xamarin.Forms之Button
    Xamarin.Forms之MessagingCenter
    Xamarin.Forms之Frame布局
    Xamarin.Forms之OnPlatform的使用
    2018/11/7 20:47:57
    2018/11/6
    2018/11/5 每日分析-test
  • 原文地址:https://www.cnblogs.com/LcxSummer/p/13045169.html
Copyright © 2011-2022 走看看