2017-01-29 8 views
0

が動作していない私は、位置を取得するには、Android 6.0でこのコードを使用しています:ロケーションコードはもう

public class MainActivity extends AppCompatActivity implements LocationListener{ 
    protected LocationManager locationManager; 
    protected LocationListener locationListener; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     if (checkPermission()) 
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); 
    } 

    @Override 
    public void onLocationChanged(Location location) { 
     lati = location.getLatitude(); 
     longi = location.getLongitude(); 
    } 

    @Override 
    public void onProviderDisabled(String provider) { 
     Log.d("Latitude", "disable"); 
    } 

    @Override 
    public void onProviderEnabled(String provider) { 
     Log.d("Latitude", "enable"); 
    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 
     Log.d("Latitude", "status"); 
    } 

    private boolean checkPermission(){ 
     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 false; 
     } 
     return true; 
    } 
} 

私がtrueにプログラムのプロパティでアクセス権を設定します。

これは以前から使用されていましたが、今は衛星や一般的な位置を見つけることはありません。

Googleマップは直ちに衛星を検出します。

変更する必要があるのは何ですか?

+0

Whats happend?エラー?どの点が見える? ?? – josedlujan

+0

何もありません。場所のアイコンが現れました。場所を探しているように見えましたが、決して見つけられませんでした。それから、私は地図を開きました。そこには、場所がすぐにありました。したがって、ハードウェアの問題ではありません。 –

+0

@ P.Dee 'compileSdkVersion'と' targetSdkVersion'を22に変更しようとしています。それがうまくいけば、そのパーミッションの問題です。あなたは 'Marshmallow +'デバイスで場所の許可を求めなければなりません。 – DwlRathod

答えて

0

あなたのコードにすべてのTODOコメントを表示しますか?それを実装する。あなたでなければなりません最新バージョンのandoridで動作するようにするには

+0

解決策はありませんが、アプリでlastfoundlocationプロパティを使用しました。 –

関連する問題