얻기 안녕하세요 아래 앱스에서 LatLong 점점 오전 :onMapReady() 메서드 호출 GoogleApiClient을 구축하기 전에 - LatLong 0.0
만든 GoogleApiClient 구축하는 나의 조각의 방법
private synchronized void buildGoogleApiClient() {
MyApp.getGoogleApiHelper().setConnectionListener(new GoogleApiHelper.ConnectionListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnected(Bundle bundle) {
//this function will call whenever google api connected or already connected when setting listener
//You are connected do what ever you want
//Like i get last known location
try {
if (!Constant.checkPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION)) {
Constant.requestPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION, PLACE_PICKER_REQUEST);
} else {
if (Constant.isOnline(mContext)) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
mCurrentLatitude = mLastLocation.getLatitude();
mCurrentLongitude = mLastLocation.getLongitude();
locationUpdate();
} else {
Constant.displayToast(mContext, getResources().getString(R.string.msg_internet));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
OnMapReady을 () 메소드는 다음과 같습니다. loadDefault() 메소드를 호출하여 현재 위치를로드합니다. 나는() 메소드 loadDefault 내부 선 아래에서 mCurrentLongitude 0.0 mCurrentLaltitude 및 을 얻고,
private void loadDefault(GoogleMap googleMap) {
try {
if (Prefrences.checkPref(mContext, NEAR_ME_SEARCH))
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Double.parseDouble(Prefrences.getPref(mContext, NEAR_ME_LAT)), Double.parseDouble(Prefrences.getPref(mContext, NEAR_ME_LNG))), 8));
else
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mCurrentLatitude, mCurrentLongitude), 8f));
} catch (MalformedParameterizedTypeException e) {
handleException(mContext, e);
} catch (Exception e) {
handleException(mContext, e);
}
}
그러나 :
public void onMapReady(final GoogleMap googleMap) {
loadDefault(googleMap);
}
내 loadDefault() 메소드는 다음과 같습니다.
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mCurrentLatitude, mCurrentLongitude), 8f));
하시기 바랍니다. 감사.
편집는 : onMapReady
가 호출되고지도가로드 된 경우
private void initialization(View rootView, Bundle savedInstanceState) {
try {
mModelBarList = BarListModel.getBarListInstance();
if (!Constant.checkPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION)) {
Constant.requestPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION, PLACE_PICKER_REQUEST);
} else {
if (Constant.isOnline(mContext)) {
mGoogleApiClient = MyApp.getGoogleApiHelper().getGoogleApiClient();
buildGoogleApiClient();
} else {
Constant.displayToast(mContext, getResources().getString(R.string.msg_internet));
}
}
mMapView = (MapView) rootView.findViewById(R.id.map);
mMapView.onCreate(savedInstanceState);
mMapView.onResume();
mMapView.getMapAsync(MapFragment.this);
}
누가'buildGoogleApiClient()'메소드를 호출하고 있습니까? 내 생각에이 메소드는 전혀 호출되지 않았거나'onMapReady()'후에 호출되고있다. Android 용 Google지도를 사용할 때 방향 변경 또는 다시로드를 통해 위치를 유지해야하는 경우 내 위치를 인스턴스 상태로 저장합니다. –
@TimBiegeleisen, 위의 조건에서지도를 더 빨리 초기화 할 수 있습니까? – Krantiz
나는 당신이 무엇을하려고하는지 모르기 때문에 정확한 답변을 드릴 수 없습니다. 액티비티가로드 될 때 값을로드 한 다음 인스턴스 상태에 저장합니다. 적어도이 작업은 수행합니다. 예를 들어 환경 설정에서 가져 오거나 SQLite 데이터베이스에서 가져온 경우와 같이 솔루션이 다를 수 있습니다. –