1
我使用的是android Mapbox SDK 4.0.0,當位置發生變化時,我無法設置地圖的中心位置。我不明白如何使用MyLocationTrackingMode。或者如何重新獲得當前的經緯度,並將它們傳遞給CameraPosition。請有人幫助我嗎?提前致謝!Mapbox跟蹤模式SDK 4.0.0
package com.detores.wristmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
public class MainActivity extends AppCompatActivity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a mapView
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
// Set map style
mapboxMap.setStyleUrl(Style.MAPBOX_STREETS);
// Set the camera's starting position
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(50.0051, 36.3562)) // set the camera's center position
.zoom(12) // set the camera's zoom level
.build();
// Move the camera to that position
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mapboxMap.setMyLocationEnabled(true);
}
});
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
}
非常感謝!它工作得很好。 –
很高興我能幫忙。如果答案有幫助,可否請[標記爲正確](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work),以便其他具有相同問題的人可以快速找到回答。 – cammace