좌표 이동시 지도 미생성 오류

chipButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
moveCamera(LatLng.from(latitude, longitude));
}
});

private void moveCamera(LatLng position) {
kakaoMap.moveCamera(CameraUpdateFactory.newCenterPosition(position));
kakaoMap.moveCamera(CameraUpdateFactory.zoomTo(10));

}

주소를 좌표로 변환하는 api를 호출해서 x와 y의 값을 double로 추출하여 각각 latitude와 longitude에 저장하고 moveCamera에 사용했는데 버튼을 누르면 지도가 하얗게 변합니다. 로그캣을 보니까 이동은 하는거 같은데 지도가 안 보입니다.
저 변수값 대신 숫자를 넣으면 하얗게 변하지 않고 잘 이동하는게 보입니다. 왜 그러는지 모르겠어요… 해시키랑 rest api 키는 정확합니다

1개의 좋아요

@YOUNG040342 Hello,

the solution for the Kakao Map API coordinate movement issue:

  1. Correct LatLng Creation
// Incorrect method
LatLng.from(latitude, longitude)

// Correct method
new LatLng(latitude, longitude)
  1. Improved Camera Movement Code
private void moveCamera(LatLng position) {
    // Combine position and zoom in one update
    CameraUpdate cameraUpdate = CameraUpdate.newCenterPositionAndZoom(position, 10);
    kakaoMap.moveCamera(cameraUpdate);
}
  1. Add Coordinate Validation
private void moveCamera(LatLng position) {
    // Validate coordinates
    if (position != null && 
        Math.abs(position.latitude) <= 90 && 
        Math.abs(position.longitude) <= 180) {
        CameraUpdate cameraUpdate = CameraUpdate.newCenterPositionAndZoom(position, 10);
        kakaoMap.moveCamera(cameraUpdate);
    } else {
        // Log error for invalid coordinates
        Log.e("MapError", "Invalid coordinates: " + position);
    }
}
  1. Debugging Logs
chipButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.d("MapDebug", "Latitude: " + latitude + ", Longitude: " + longitude);
        moveCamera(new LatLng(latitude, longitude));
    }
});

Potential Causes of White Screen:

  • Incorrect coordinate conversion
  • Incomplete map initialization
  • Coordinate system mismatch

Comprehensive Example:

private void initMap() {
    MapView mapView = new MapView(this);
    mapContainer.addView(mapView);
    kakaoMap = mapView.getMapView();
    
    // Set initial position
    kakaoMap.moveCamera(CameraUpdate.newCenterPositionAndZoom(
        new LatLng(37.5665, 126.9780), // Default Seoul coordinates
        10
    ));
}

chipButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        try {
            // Log coordinates
            Log.d("MapDebug", "Moving to - Lat: " + latitude + ", Lng: " + longitude);
            
            // Move camera
            LatLng targetPosition = new LatLng(latitude, longitude);
            CameraUpdate cameraUpdate = CameraUpdate.newCenterPositionAndZoom(targetPosition, 10);
            kakaoMap.moveCamera(cameraUpdate);
        } catch (Exception e) {
            Log.e("MapError", "Camera move error", e);
        }
    }
});

To help further, please provide:

  • Coordinate conversion API call code
  • How latitude and longitude are set
  • Map initialization code
  • Full error messages from logcat