좋아요, 그래서 조각과 내 탐색 창에서지도가 있습니다. 지도가로드되면 앱이 실행되고 현재 위치를 가리 킵니다. 이제 나는 네비게이션 목록에 자신의 라트와 롱이있는 장소를 거의 추가하지 않았습니다. 이제 내가 원하는 것은 내 탐색 창에서 그러한 장소 중 하나를 클릭 할 때마다지도 조각을 다시로드하지 않고지도에서 현재 설정된 마커를 변경하지 않고도 그 장소로 이동한다는 것입니다.지도의 특정 위치로 이동할 수없는 탐색 드로어 android에서 조각화
다음은 탐색 창에서 각 항목을 클릭 할 때 호출되는 SelectItem 메소드입니다. 이 방법은 내가 탐색 창에서 항목을 클릭 이러한 코드 매번로 지금 ... 내 응용 프로그램
public void SelectItem(int possition) {
Fragment fragment = null;
Bundle args = new Bundle();
fragment = new MAPFragment();
Log.e("In main activity","Lets see what happens");
String[] coords = dataList.get(possition).getGeo().split(",");
Double c1 = new Double(Double.valueOf(coords[0]));
Double c2 = new Double(Double.valueOf(coords[1]));
fragment.setArguments(args);
FragmentManager frgManager = getFragmentManager();
final Fragment existingFragment = frgManager.findFragmentById(R.id.map);
if(existingFragment !=null){
((receiveData)existingFragment).navigateToNewLocation(c1,c2);
}
else
frgManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(possition, true);
setTitle(dataList.get(possition).getItemName());
mDrawerLayout.closeDrawer(mDrawerList);
}
여기 내지도 조각이야의 MainActivity에
interface receiveData{
public void navigateToNewLocation(double lat, double lon);}
public class MAPFragment extends Fragment implements receiveData {
public String IMAGE_RESOURCE_ID = "iconResourceID";
public String ITEM_NAME = "itemName";
public String GEO = "39.933333,32.866667";
public void setParameters(double lat, double lon){
navigateToNewLocation(lat, lon);
}
// Google Map
private GoogleMap googleMap;
ImageView ivIcon;
TextView tvItemName;
MapView mapView;
String[] coords = GEO.split(",");
Double c1 = new Double(Double.valueOf(coords[0]));
Double c2 = new Double(Double.valueOf(coords[1]));
public MAPFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_layout_one, container,
false);
Log.e("coords[0]",coords[0]);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
return view;
}
/**
* function to load map. If map is not created it will create it for you
* */
public void initilizeMap() {
if (googleMap==null){
googleMap=((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
googleMap.getUiSettings().setRotateGesturesEnabled(true);
googleMap.setMyLocationEnabled(true);
Log.e("In MAPFragment","Before coords!=null");
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(c1,c2)));
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
if(location!=null){
onLocationChanged(location);
}
googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location arg0) {
// TODO Auto-generated method stub
}
});
//checking
if(googleMap==null){
Toast.makeText(getActivity().getApplicationContext(), "Unable to create", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onResume() {
super.onResume();
initilizeMap();
}
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
// Getting latitude of the current location
double latitude = location.getLatitude();
// Getting longitude of the current location
double longitude = location.getLongitude();
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
// Showing the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
@Override
public void onDestroyView()
{
super.onDestroy();
mapView.onDestroy();
}
public void navigateToNewLocation(double lat, double lon){
Log.e("INSIDE navigateToNewLoc","next is cam pos");
// On clicking a user
CameraPosition cameraPosition = new CameraPosition.Builder().target(
new LatLng(lat,lon)).zoom(12).build();
Log.e("INSIDE navigateToNewLoc","next is animateCam");
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
존재, 응용 프로그램이 실패합니다 .. .. 난은
((receiveData)existingFragment).navigateToNewLocation(c1,c2);
가 여기 내 로그 고양이
의이 SelectItem 방법에 매우 라인 때문에이의 클래스 캐스트 예외의 발생 추측09-10 03:00:00.784: E/AndroidRuntime(31030): FATAL EXCEPTION: main
09-10 03:00:00.784: E/AndroidRuntime(31030): Process: com.findmeWithdrawer, PID: 31030
09-10 03:00:00.784: E/AndroidRuntime(31030): java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to com.findmeWithdrawer.receiveData
09-10 03:00:00.784: E/AndroidRuntime(31030): at com.findmeWithdrawer.MainActivity.SelectItem(MainActivity.java:205)
안녕하세요 위 코드를 편집했습니다 ... 메소드가 부분적으로 작동했습니다 ...하지만 클래스 캐스트 예외가 존재합니다 ... 그리고 수정 방법을 모릅니다. ------- java.lang .ClassCastException : com.google.android.gms.maps.MapFragment를 com.findmeWithdrawer.receiveData로 캐스팅 할 수 없음 –
existingFragment 변수의 데이터 유형은 무엇입니까? MAPFragment 클래스 (작성한 클래스) 또는 Google의 MapFragment (com.google.android.gms.maps.MapFragment)입니까? 예를 들어 Log.i ("yourtag", existingFragment.getClass(). getSimpleName()) – alpinescrambler
안녕하세요, 방금 Log CAT 데이터를 추가 했으므로 LogCat tostring을 추가하십시오. –