【问题标题】:location with internet service provider(network provider)与互联网服务提供商(网络提供商)的位置
【发布时间】:2014-04-07 01:39:05
【问题描述】:

您好,我有一个查找您位置的课程,首先使用网络提供商,然后等待 GPS 提供商信息。我不知道为什么,但我从来没有从网络提供商那里得到信息,GPS 在获取信号时工作得很好。

public class GpsListener {

    public static GpsListener refrence = null ;
    public LocationManager locationManager = null;
    public LocationListener locationListener = null;
    public Location location = null;

    public static GpsListener getInstance(){
        if(refrence == null){
            refrence = new GpsListener();
        }
        return refrence;
    }

    public void startGpsCallBack(Context activityContext){
        locationManager = (LocationManager) activityContext.getSystemService(Context.LOCATION_SERVICE);
        locationListener = new mylocationlistener();
        locationManager.requestLocationUpdates(
                LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
        location = locationManager
                .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null) {
            Map.MyPositionlatitude = location.getLatitude();
            Map.MyPositionlongitude = location.getLongitude();
        }
    }

    public class mylocationlistener implements LocationListener {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                  Map.MyPositionlatitude = location.getLatitude();
                  Map.MyPositionlongitude = location.getLongitude();
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    }

    public void stopGpsCallBack(){
        if (locationManager != null) {
            locationManager.removeUpdates(locationListener);
        }
    }

    public void startGpsCallbackAgain(Context activityContext){
        locationManager = (LocationManager) activityContext.getSystemService(Context.LOCATION_SERVICE);
        locationListener = new mylocationlistener();
        locationManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 0, 0, locationListener);
        location = locationManager
        .getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (location != null) {
              Map.MyPositionlatitude = location.getLatitude();
              Map.MyPositionlongitude = location.getLongitude();
        }
    }

}

【问题讨论】:

  • 我将第二个提供商从GPS_PROVIDER 更改为PASSIVE,这种方法是否正确?
  • 你真正想要什么?

标签: android gps location


【解决方案1】:

使用google play服务更简单

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    • 2013-11-01
    • 1970-01-01
    • 2012-02-22
    • 1970-01-01
    相关资源
    最近更新 更多