나는 자료가 명부 작성의 모양으로 보여지는 신청에서 일하고있다. 사용자가 목록 항목을 클릭하면 특정 목록 항목의 세부 정보가 표시됩니다. 이제 응용 프로그램에 모든 데이터를 표시 할 수 있습니다. 그러나 나는 위치를 보여줘야하는 Google지도에서 문제가 발생했습니다. 내 응용 프로그램이 처음 시작될 때지도 (Image)에 위치를 볼 수 있지만 두 번째로 응용 프로그램을 시작할 때지도 (Image)의 위치를 볼 수 없습니다. 나는 이것에 완전히 붙어 있고 내가 뭘 잘못하고 있는지 얻지 못하고있다. 이 문제를 해결하도록 안내해주십시오.마시맬로에서 위도와 경도를 표시하는 방법은 무엇입니까?
에서 onCreate
mFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mFragment.getMapAsync(this);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(5000); //5 seconds
mLocationRequest.setFastestInterval(3000); //3 seconds
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
내가 준비
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onResume() {
super.onResume();
if(mGoogleApiClient.isConnected()){
requestLocationUpdates();
}
}
@Override
protected void onStop() {
super.onStop();
mGoogleApiClient.disconnect();
}
@Override
public void onMapReady(GoogleMap googleMap) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mGoogleMap = googleMap;
LatLng latlng = new LatLng(lat, lon);
mGoogleMap.addMarker(new MarkerOptions().position(latlng).title("Marker"));
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSION_FINE_LOCATION);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case MY_PERMISSION_FINE_LOCATION:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
requestLocationUpdates();
}
} else {
Toast.makeText(Property_Detail.this, "App Require Permission", Toast.LENGTH_SHORT).show();
finish();
}
break;
}
}
@Override
public void onConnected(Bundle bundle) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
requestLocationUpdates();
}
}
@Override
public void onConnectionSuspended(int i) {
Toast.makeText(this,"onConnectionSuspended",Toast.LENGTH_SHORT).show();
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Toast.makeText(this,"onConnectionFailed",Toast.LENGTH_SHORT).show();
}
private void requestLocationUpdates() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mGoogleMap.clear();
latLng = new LatLng(lat, lon);
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
mCurrLocation = mGoogleMap.addMarker(markerOptions);
}
}
@Override
public void onLocationChanged(Location location) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
myLatitude = lat;
myLongitude = lon;
}
}
가 난 당신이해야 추측 변수 위도와 당신이지도에서 사용하는 범위 c를 준비가 – Ak9637
대답은 같이 시도 –
지도 아래에서 먼저지도를로드하고 싶을 때 작업하십시오. – Ak9637