私は、現在の位置を取得し、リアルタイムで緯度と経度を表示するアプリケーションを作成しようとしています。しかし、私はこのアプリケーションを実行すると、GPSは、場所を検索し、修正を取得しようとしないようです。なぜこれが起こっているのか分かりません。私は何かを逃したことがありますか?マップアプリを開くと、その場所にすぐに修正が加えられます。しかし、私のアプリでは、gpsが通知バーで1つまたは少なくともathereを検索していないため、通常はマップアプリケーションによって表示される「gpsの検索」のようなものは表示されません。融合位置が機能しないAndroid
私の主な活動:
package com.example.android.location1;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, LocationListener{
private final String LOG_TAG = "TestApp";
private TextView txtOutput;
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
private static final int REQUEST_PERMISSION = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).build();
txtOutput = (TextView) findViewById(R.id.txtOutput);
}
@Override
protected void onStart(){
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop(){
mGoogleApiClient.disconnect();
super.onStop();
}
@Override
public void onConnected(Bundle bundle){
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(1000).setMaxWaitTime(2000);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSION);
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
@Override
public void onConnectionSuspended(int i){
Log.i(LOG_TAG, "GoogleApiClient connection has been suspended.");
}
@Override
public void onLocationChanged(Location location){
Log.i(LOG_TAG, location.toString());
txtOutput.setText(String.valueOf(location.getLatitude()) + ", " + String.valueOf(location.getLongitude()));
}
}
私のマニフェストファイル:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.location1">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.location.gps"/>
<uses-feature android:name="android.hardware.location.network"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
私はそれらのいずれかで動作しませんアンドロイド6および7でこれをテストしています。どんな助けもありがとう。
あなたの解決方法では問題は解決していません。問題は依然として続きます。 – speedster01
は、次の手順を実行し https://developers.google.com/android/guides/setupあなたmGoogleApiClientが認証され、監視ログにとonConnected()メソッドがコールバックGoogleApiClient.ConnectionCallbacksで実行されていることを接続されます チェック – typecode
あなたが提供したリンクは、最初に機能を設定するためにのみ使用しました。私がチェックしました; Googleクライアントが接続され、onConnected()メソッドも実行されます。 locationChanged()メソッドも呼び出されます。ちょうどそれは何度も同じ場所です。場所は、通知メニューに表示されていないGPSアイコン以外は変更されていないようです。 – speedster01