1
Google지도를 사용하여 현재 위치를 표시하려고합니다. '위치'가 전화 (갤럭시 s4)에서 켜져있는 한 잘 실행됩니다. 하지만 전화로 '위치 정보'를 끄면 충돌이 발생합니다.위치 앱이 손상되는 이유
로그 캣은 공급자를 말하고 다음 줄에 널 (null)입니다
Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
내가 대신 응용 프로그램 충돌의 "위치에 회전을 말하는 메시지를 팝업합니다.에 대한 간단한 & 좋은 방법 일 것입니다 무슨 그렇게
코드 :
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
private Marker marker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(32, 270)).title("Marker"));
mMap.setMyLocationEnabled(true);
LocationManager locationManager= (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 14));
}
}
정확히 스택 추적이란 무엇입니까? – stkent
어쩌면 당신은 http://stackoverflow.com/questions/3470693/android-get-location-or-prompt-to-enable-location-service-if-disabled – k3v1n4ud3
잘 모르겠습니다. 한 달 전에 나는 자바의 기본조차 몰랐다. 여기서 내 목표를 달성하기 위해 통과해야 할 주제는 무엇입니까? –