0
我想解決問題,並且我無法確定如何。我需要通過GPS跟蹤我的應用程序位置,不跟蹤網絡和互聯網。現在,當我在外面,我有錯誤的立場,以非常大的分歧來找我。需要以100米的精度定位。GoogleMaps API v2 - 僅通過GPS跟蹤
這裏是我的活動
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
private boolean aFoundMyLocation;
private Document aDocument;
private GoogleMap aGoogleMap;
private GoogleDirection aGoogleDirection;
private LatLng aCurrentLocation;
...
@InjectView(R.id.txt_distance)
TextView txtDistance;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
// initial map center settings
aTargetLocation = new LatLng(49.199362, 18.737382);
aGoogleDirection = new GoogleDirection(this);
aFoundMyLocation = false;
// inflate mapFragment
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
...
@Override
public void onMapReady(GoogleMap googleMap) {
aGoogleMap = googleMap;
aGoogleMap.setBuildingsEnabled(true);
aGoogleMap.setMyLocationEnabled(true);
aGoogleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location location) {
aCurrentLocation = new LatLng(location.getLatitude(), location.getLongitude());
...
}
}
});
}
}
和我的清單
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
...
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="..." />
</application>
可有人的一部分給了我一個建議,如何可以編輯這個只通過100米的精度GPS跟蹤實際位置? ?謝謝
on requestLocationUpdates,最後param上下文偵聽器不能解決,有想法我必須改變? – Tomino
「this」是指應用程序的位置偵聽器。確保你有這個:'import android.location.LocationListener' – charoup
好的,謝謝,壞的導入,我是從google.android.gms.maps ...我會去嘗試外 – Tomino