2017-09-20 6 views
2

私は現在、オンになっていない場合にGPSを有効にするようにユーザに促すアンドロイドアプリを開発しており、この目的のためにアラートダイアログを使用しています。私は設定から​​GPSを有効にし、戻るボタンを押して私のアプリに戻ってくると、トーストメッセージ0.00,0.00を表示します。私はアプリを実行する前に私のGPSを持っているが、アプリが適切に私の場所を表示します。私は、GPSの目的を有効にした後に、このリフレッシュユーザーの場所に使用する方法を知りたいと思います。すべての関連記事が本当に助けになるでしょう。アプリのプロンプトからgpsを有効にした後、最新の場所を更新して取得する方法は?

これは、GPSを有効にした後、現在位置を取得するためのコードの下の私のGPSクラス

  public class GpsTracker extends Service implements LocationListener { 

private final Context mContext; 

// flag for GPS status 
boolean isGPSEnabled = false; 

// flag for network status 
boolean isNetworkEnabled = false; 

// flag for GPS status 
boolean canGetLocation = false; 

Location location; // location 
double latitude; // latitude 
double longitude; // longitude 

// The minimum distance to change Updates in meters 
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters 

// The minimum time between updates in milliseconds 
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute 

// Declaring a Location Manager 
protected LocationManager locationManager; 

public GpsTracker(Context context) { 
    this.mContext = context; 
    getLocation(); 
} 

public Location getLocation() { 
    try { 
     locationManager = (LocationManager) mContext 
       .getSystemService(LOCATION_SERVICE); 

     // getting GPS status 
     isGPSEnabled = locationManager 
       .isProviderEnabled(LocationManager.GPS_PROVIDER); 

     // getting network status 
     isNetworkEnabled = locationManager 
       .isProviderEnabled(LocationManager.NETWORK_PROVIDER); 

     if (!isGPSEnabled && !isNetworkEnabled) { 
      // no network provider is enabled 
     } else { 
      if (ActivityCompat.checkSelfPermission(mContext, 
      Manifest.permission.ACCESS_FINE_LOCATION) != 
       PackageManager.PERMISSION_GRANTED 
        && ActivityCompat.checkSelfPermission(mContext, 
         Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 

       return null; 
      } 
      this.canGetLocation = true; 
      // First get location from Network Provider 
      if (isNetworkEnabled) { 

       /* locationManager.requestLocationUpdates(
         LocationManager.NETWORK_PROVIDER, 
         MIN_TIME_BW_UPDATES, 
         MIN_DISTANCE_CHANGE_FOR_UPDATES, this);*/ 
       Log.d("Network", "Network"); 
       if (locationManager != null) { 
        location = locationManager 
          .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
        if (location != null) { 
         latitude = location.getLatitude(); 
         longitude = location.getLongitude(); 
        } 
       } 
      } 
      // if GPS Enabled get lat/long using GPS Services 
      if (isGPSEnabled) { 
       if (location == null) { 
        if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED 
          && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 

         return null; 
        } 
        /* locationManager.requestLocationUpdates(
          LocationManager.GPS_PROVIDER, 
          MIN_TIME_BW_UPDATES, 
          MIN_DISTANCE_CHANGE_FOR_UPDATES, this);*/ 
        Log.d("GPS Enabled", "GPS Enabled"); 
        if (locationManager != null) { 
         location = locationManager 
           .getLastKnownLocation(LocationManager.GPS_PROVIDER); 
         if (location != null) { 
          latitude = location.getLatitude(); 
          longitude = location.getLongitude(); 
         } 
        } 
       } 
      } 
     } 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    return location; 
} 

/** 
* Stop using GPS listener 
* Calling this function will stop using GPS in your app 
* */ 
public void stopUsingGPS(){ 

    if(locationManager != null){ 
     if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED 
       && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 

      return ; 
     } 
     locationManager.removeUpdates(GpsTracker.this); 
    } 
} 

/** 
* Function to get latitude 
* */ 
public double getLatitude(){ 
    if(location != null){ 
     latitude = location.getLatitude(); 
    } 

    // return latitude 
    return latitude; 
} 

/** 
* Function to get longitude 
* */ 
public double getLongitude(){ 
    if(location != null){ 
     longitude = location.getLongitude(); 
    } 

    // return longitude 
    return longitude; 
} 

/** 
* Function to check GPS/wifi enabled 
* @return boolean 
* */ 
public boolean canGetLocation() { 
    return this.canGetLocation; 
} 

/** 
* Function to show settings alert dialog 
* On pressing Settings button will lauch Settings Options 
* */ 
public void showSettingsAlert(){ 
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext); 

    // Setting Dialog Title 
    alertDialog.setTitle("GPS is settings"); 

    // Setting Dialog Message 
    alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?"); 

    // On pressing Settings button 
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
      mContext.startActivity(intent); 

     } 
    }); 

    // on pressing cancel button 
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      dialog.cancel(); 
     } 
    }); 

    // Showing Alert Message 
    alertDialog.show(); 
} 

@Override 
public void onLocationChanged(Location location) { 
} 

@Override 
public void onProviderDisabled(String provider) { 
} 

@Override 
public void onProviderEnabled(String provider) { 
} 

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

@Override 
public IBinder onBind(Intent arg0) { 
    return null; 
} 

} 
+0

場所のプロンプトユーザーにチェックこれを:https://stackoverflow.com/questions/40142331/how-to-request-location-permission-on-android-6 – A2N

答えて

0

私も、問題に直面していますこれを試してみてください。 reload your activityその後

  • にあなたが持っている

    • 、あなたはlocation

    • あなたはenable or disableGpsする場合はalert is in try catch to avoid crashを確認してくださいgps tracker class
    • booleanを取ることができます。

    public class GpsTracker extends Service implements LocationListener { 
    
    private final Context mContext; 
    
    public static boolean isFromSetting=false; 
    // flag for GPS status 
    boolean isGPSEnabled = false; 
    
    // flag for network status 
    boolean isNetworkEnabled = false; 
    
    // flag for GPS status 
    boolean canGetLocation = false; 
    
    Location location; // location 
    double latitude; // latitude 
    double longitude; // longitude 
    
    // The minimum distance to change Updates in meters 
        private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 
        meters 
    
    // The minimum time between updates in milliseconds 
    private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute 
    
    // Declaring a Location Manager 
    protected LocationManager locationManager; 
    
    public GpsTracker(Context context) { 
    this.mContext = context; 
    getLocation(); 
    } 
    
        public Location getLocation() { 
    try { 
        locationManager = (LocationManager) mContext 
          .getSystemService(LOCATION_SERVICE); 
    
        // getting GPS status 
        isGPSEnabled = locationManager 
          .isProviderEnabled(LocationManager.GPS_PROVIDER); 
    
        // getting network status 
        isNetworkEnabled = locationManager 
          .isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
    
        if (!isGPSEnabled && !isNetworkEnabled) { 
         // no network provider is enabled 
        } else { 
         if (ActivityCompat.checkSelfPermission(mContext, 
        Manifest.permission.ACCESS_FINE_LOCATION) != 
         PackageManager.PERMISSION_GRANTED 
           && ActivityCompat.checkSelfPermission(mContext, 
        Manifest.permission.ACCESS_COARSE_LOCATION) != 
        PackageManager.PERMISSION_GRANTED) { 
    
          return null; 
         } 
         this.canGetLocation = true; 
         // First get location from Network Provider 
         if (isNetworkEnabled) { 
    
          /* locationManager.requestLocationUpdates(
            LocationManager.NETWORK_PROVIDER, 
            MIN_TIME_BW_UPDATES, 
            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);*/ 
          Log.d("Network", "Network"); 
          if (locationManager != null) { 
           location = locationManager 
             .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
           if (location != null) { 
            latitude = location.getLatitude(); 
            longitude = location.getLongitude(); 
           } 
          } 
         } 
         // if GPS Enabled get lat/long using GPS Services 
         if (isGPSEnabled) { 
          if (location == null) { 
           if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED 
             && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
    
            return null; 
           } 
           /* locationManager.requestLocationUpdates(
             LocationManager.GPS_PROVIDER, 
             MIN_TIME_BW_UPDATES, 
             MIN_DISTANCE_CHANGE_FOR_UPDATES, this);*/ 
           Log.d("GPS Enabled", "GPS Enabled"); 
           if (locationManager != null) { 
            location = locationManager 
              .getLastKnownLocation(LocationManager.GPS_PROVIDER); 
            if (location != null) { 
             latitude = location.getLatitude(); 
             longitude = location.getLongitude(); 
            } 
           } 
          } 
         } 
        } 
    
    } catch (Exception e) { 
        e.printStackTrace(); 
    } 
    
    return location; 
        } 
    
        /** 
        * Stop using GPS listener 
        * Calling this function will stop using GPS in your app 
        * */ 
        public void stopUsingGPS(){ 
    
    if(locationManager != null){ 
        if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED 
          && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
    
         return ; 
        } 
        locationManager.removeUpdates(GpsTracker.this); 
        } 
    } 
    
        /** 
         * Function to get latitude 
         * */ 
        public double getLatitude(){ 
        if(location != null){ 
        latitude = location.getLatitude(); 
        } 
    
        // return latitude 
        return latitude; 
        } 
    
        /** 
        * Function to get longitude 
        * */ 
         public double getLongitude(){ 
         if(location != null){ 
         longitude = location.getLongitude(); 
         } 
    
         // return longitude 
         return longitude; 
         } 
    
         /** 
         * Function to check GPS/wifi enabled 
         * @return boolean 
         * */ 
         public boolean canGetLocation() { 
         return this.canGetLocation; 
         } 
    
         /** 
         * Function to show settings alert dialog 
         * On pressing Settings button will lauch Settings Options 
         * */ 
         public void showSettingsAlert(){ 
         try{ 
         AlertDialog.Builder alertDialog = new 
         AlertDialog.Builder(mContext); 
    
          // Setting Dialog Title 
          alertDialog.setTitle("GPS is settings"); 
    
         // Setting Dialog Message 
          alertDialog.setMessage("GPS is not enabled. Do you want to go 
          to settings menu?"); 
    
          // On pressing Settings button 
          alertDialog.setPositiveButton("Settings", new 
          DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int which) { 
           Intent intent = new 
          Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
          isFromSetting = true; 
          mContext.startActivity(intent); 
    
         } 
          }); 
    
          // on pressing cancel button 
          alertDialog.setNegativeButton("Cancel", new 
          DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int which) { 
          dialog.cancel(); 
          } 
          }); 
    
    // Showing Alert Message 
    alertDialog.show(); 
         }catch(Exception e){e.printstacktrace} 
         } 
    
         @Override 
        public void onLocationChanged(Location location) { 
         } 
    
         @Override 
         public void onProviderDisabled(String provider) { 
         } 
    
         @Override 
         public void onProviderEnabled(String provider) { 
         } 
    
         @Override 
         public void onStatusChanged(String provider, int status, Bundle 
         extras) { 
         } 
    
         @Override 
         public IBinder onBind(Intent arg0) { 
         return null; 
         } 
         } 
    

    • あなたは何MainActivity.javaではこの

    @Override 
    protected void onResume() { 
        super.onResume(); 
        if (GPSTracker.isFromSetting==true){ 
          finish(); 
          startActivity(getIntent()); 
          GPSTracker.isFromSetting=false; 
         } 
        } 
         @Override 
         public void onBackPressed() { 
          super.onBackPressed(); 
         if (GPSTracker.isFromSetting==true){ 
          finish(); 
          startActivity(getIntent()); 
          GPSTracker.isFromSetting=false; 
          } 
          } 
         @Override 
        protected void onCreate(@Nullable Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
         gps = new GPSTracker(LoginActivity.this); 
    
        if(gps.canGetLocation()){ 
    
         double latitude = gps.getLatitude(); 
         double longitude = gps.getLongitude(); 
    
         Log.e("55",""+latitude); 
         Log.e("56",""+longitude); 
         Toast.makeText(getApplicationContext(), "Your Location is - \nLat: "     
         + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show(); 
         }else{ 
    
          gps.showSettingsAlert(); 
          } 
         } 
    

    あなたを助けてくれることを嬉しく思います。

  • +1

    それは働いていますありがとう –

    1

    の使用です。

    public class MainActivity extends AppCompatActivity implements LocationListener, 
        GoogleApiClient.ConnectionCallbacks, 
        GoogleApiClient.OnConnectionFailedListener, OnMapReadyCallback { 
    
    final String TAG = "GPS"; 
    GoogleMap googleMap; 
    Marker mCurrLocationMarker; 
    private long UPDATE_INTERVAL = 2 * 1000; /* 10 secs */ 
    private long FASTEST_INTERVAL = 2000; /* 2 sec */ 
    static final int MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1; 
    private static final int GPS_CHECK = 112; 
    GoogleApiClient gac; 
    LocationRequest locationRequest; 
    TextView tvLatitude, tvLongitude, tvTime; 
    LocationManager locationManager; 
    Button capture; 
    
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        tvLatitude = (TextView) findViewById(R.id.tvLatitude); 
        tvLongitude = (TextView) findViewById(R.id.tvLongitude); 
        tvTime = (TextView) findViewById(R.id.tvTime); 
        capture = (Button) findViewById(R.id.capture); 
    
        isGooglePlayServicesAvailable(); 
    
        //  if (!isLocationEnabled()) 
        //   showAlert(); 
    
        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { 
         showAlert(); 
        } 
    
        locationRequest = new LocationRequest(); 
        locationRequest.setInterval(UPDATE_INTERVAL); 
        locationRequest.setFastestInterval(FASTEST_INTERVAL); 
        locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); 
        gac = new GoogleApiClient.Builder(this) 
          .addConnectionCallbacks(this) 
          .addOnConnectionFailedListener(this) 
          .addApi(LocationServices.API) 
          .build(); 
    
        SupportMapFragment mapFragment = (SupportMapFragment) 
          getSupportFragmentManager() 
            .findFragmentById(R.id.map); 
    
        mapFragment.getMapAsync(this); 
    } 
    
    @Override 
    protected void onStart() { 
        gac.connect(); 
        super.onStart(); 
    } 
    
    @Override 
    protected void onStop() { 
        gac.disconnect(); 
        super.onStop(); 
    } 
    
    @Override 
    public void onLocationChanged(Location location) { 
        if (location != null) { 
         updateUI(location); 
        } 
    } 
    
    @Override 
    public void onConnected(@Nullable Bundle bundle) { 
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) 
          != PackageManager.PERMISSION_GRANTED 
          && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) 
          != PackageManager.PERMISSION_GRANTED) { 
         ActivityCompat.requestPermissions(MainActivity.this, 
           new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 
           MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); 
    
         return; 
        } 
        Log.d(TAG, "onConnected"); 
    
        Location ll = LocationServices.FusedLocationApi.getLastLocation(gac); 
        Log.d(TAG, "LastLocation: " + (ll == null ? "NO LastLocation" : ll.toString())); 
    
        updateUI(ll); 
    
        LocationServices.FusedLocationApi.requestLocationUpdates(gac, locationRequest, this); 
    } 
    
    @Override 
    public void onRequestPermissionsResult(
         int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 
    
        switch (requestCode) { 
         case MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION: { 
          // If request is cancelled, the result arrays are empty. 
          if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
           Toast.makeText(MainActivity.this, "Permission was granted!", Toast.LENGTH_LONG).show(); 
    
           try { 
            LocationServices.FusedLocationApi.requestLocationUpdates(
              gac, locationRequest, this); 
           } catch (SecurityException e) { 
            Toast.makeText(MainActivity.this, "SecurityException:\n" + e.toString(), Toast.LENGTH_LONG).show(); 
           } 
          } else { 
           Toast.makeText(MainActivity.this, "Permission denied!", Toast.LENGTH_LONG).show(); 
          } 
          return; 
         } 
        } 
    } 
    
    @Override 
    public void onConnectionSuspended(int i) { 
    } 
    
    @Override 
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 
        Toast.makeText(MainActivity.this, "onConnectionFailed: \n" + connectionResult.toString(), 
          Toast.LENGTH_LONG).show(); 
        Log.d("DDD", connectionResult.toString()); 
    } 
    
    private void updateUI(Location loc) { 
        Log.d(TAG, "updateUI"); 
        try { 
         tvLatitude.setText(Double.toString(loc.getLatitude())); 
         tvLongitude.setText(Double.toString(loc.getLongitude())); 
         tvTime.setText(DateFormat.getTimeInstance().format(loc.getTime())); 
    
         double lattitude = loc.getLatitude(); 
         double longitude = loc.getLongitude(); 
    
         //Place current location marker 
         LatLng latLng = new LatLng(lattitude, longitude); 
    
    
         if(mCurrLocationMarker!=null){ 
          mCurrLocationMarker.setPosition(latLng); 
         }else{ 
          mCurrLocationMarker = googleMap.addMarker(new MarkerOptions() 
            .position(latLng) 
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)) 
            .title("I am here")); 
         } 
    
         googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18)); 
         googleMap.getUiSettings().setZoomControlsEnabled(true); 
        } 
        catch (Exception e) 
        { 
    
        } 
    } 
    
    private boolean isLocationEnabled() { 
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
        return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || 
          locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
    } 
    
    private boolean isGooglePlayServicesAvailable() { 
        final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000; 
        GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); 
        int resultCode = apiAvailability.isGooglePlayServicesAvailable(this); 
        if (resultCode != ConnectionResult.SUCCESS) { 
         if (apiAvailability.isUserResolvableError(resultCode)) { 
          apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST) 
            .show(); 
         } else { 
          Log.d(TAG, "This device is not supported."); 
          finish(); 
         } 
         return false; 
        } 
        Log.d(TAG, "This device is supported."); 
        return true; 
    } 
    
    private void showAlert() { 
        final AlertDialog.Builder dialog = new AlertDialog.Builder(this); 
        dialog.setTitle("Enable Location") 
          .setMessage("Your Locations Settings is set to 'Off'.\nPlease Enable Location to " + 
            "use this app") 
          .setPositiveButton("Location Settings", new DialogInterface.OnClickListener() { 
           @Override 
           public void onClick(DialogInterface paramDialogInterface, int paramInt) { 
            startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), GPS_CHECK); 
           } 
          }) 
          .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
           @Override 
           public void onClick(DialogInterface paramDialogInterface, int paramInt) { 
    
           } 
          }); 
        dialog.show(); 
    } 
    
    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
        super.onActivityResult(requestCode, resultCode, data); 
        if (requestCode == GPS_CHECK) { 
         if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { 
          capture.setVisibility(View.GONE); 
          Toast.makeText(getApplicationContext(), "Please turn on gps...", Toast.LENGTH_SHORT).show(); 
          Log.e("BBBBBBBBBBBBBBB", ""); 
         } 
         else 
         { 
          gac.connect(); 
          googleMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() { 
    
           @Override 
           public boolean onMyLocationButtonClick() 
           { 
            try 
            { 
             Location myLocation = googleMap.getMyLocation(); 
             onLocationChanged(myLocation); 
            } 
            catch (Exception e) 
            { 
             Log.getStackTraceString(e); 
            } 
            return false; 
           } 
          }); 
         } 
        } 
    
    } 
    
    @Override 
    public void onMapReady(GoogleMap map) { 
        googleMap = map; 
        map.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
         // TODO: Consider calling 
         // ActivityCompat#requestPermissions 
         // here to request the missing permissions, and then overriding 
         // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
         //           int[] grantResults) 
         // to handle the case where the user grants the permission. See the documentation 
         // for ActivityCompat#requestPermissions for more details. 
         return; 
        } 
        map.setMyLocationEnabled(true); 
        map.setTrafficEnabled(true); 
        map.setIndoorEnabled(true); 
        map.setBuildingsEnabled(true); 
        map.getUiSettings().setZoomControlsEnabled(true); 
    } 
    } 
    
    +0

    おかげでウルheplをバディにも便利です –

    +0

    私の答えをupvoteマークしてください... –

    0

    スレッドやサービスをある程度の時間間隔で使用して、そのスレッドやサービスで長い時間を取得できます。このようなものはありません。

    mHandler=new Handler(); 
        mRunnable=new Runnable() { 
         @Override 
         public void run() {get your lat long here 
    
    
          mHandler.postDelayed(this,DELAY_TIME); 
         } 
        }; 
    
        mHandler.postDelayed(mRunnable,DELAY_TIME); 
    
    関連する問題